Search2 fixups (#3533)
Fixes several issues with focus and unbound actions. Release Notes: - N/A
This commit is contained in:
commit
ea708c50f0
2 changed files with 27 additions and 14 deletions
|
@ -5,7 +5,7 @@ use gpui::{
|
||||||
Action, ClickEvent, Div, ElementId, EventEmitter, InteractiveElement, ParentElement, Render,
|
Action, ClickEvent, Div, ElementId, EventEmitter, InteractiveElement, ParentElement, Render,
|
||||||
Stateful, Styled, Subscription, View, ViewContext, WeakView,
|
Stateful, Styled, Subscription, View, ViewContext, WeakView,
|
||||||
};
|
};
|
||||||
use search::BufferSearchBar;
|
use search::{buffer_search, BufferSearchBar};
|
||||||
use ui::{prelude::*, ButtonSize, ButtonStyle, Icon, IconButton, IconSize, Tooltip};
|
use ui::{prelude::*, ButtonSize, ButtonStyle, Icon, IconButton, IconSize, Tooltip};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
item::ItemHandle, ToolbarItemEvent, ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
|
@ -64,12 +64,14 @@ impl Render for QuickActionBar {
|
||||||
"toggle buffer search",
|
"toggle buffer search",
|
||||||
Icon::MagnifyingGlass,
|
Icon::MagnifyingGlass,
|
||||||
!self.buffer_search_bar.read(cx).is_dismissed(),
|
!self.buffer_search_bar.read(cx).is_dismissed(),
|
||||||
Box::new(search::buffer_search::Deploy { focus: false }),
|
Box::new(buffer_search::Deploy { focus: false }),
|
||||||
"Buffer Search",
|
"Buffer Search",
|
||||||
{
|
{
|
||||||
let buffer_search_bar = self.buffer_search_bar.clone();
|
let buffer_search_bar = self.buffer_search_bar.clone();
|
||||||
move |_, cx| {
|
move |_, cx| {
|
||||||
buffer_search_bar.update(cx, |search_bar, cx| search_bar.toggle(cx));
|
buffer_search_bar.update(cx, |search_bar, cx| {
|
||||||
|
search_bar.toggle(&buffer_search::Deploy { focus: true }, cx)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
|
|
@ -170,14 +170,25 @@ impl Render for BufferSearchBar {
|
||||||
|
|
||||||
h_stack()
|
h_stack()
|
||||||
.key_context("BufferSearchBar")
|
.key_context("BufferSearchBar")
|
||||||
.when(in_replace, |this| {
|
|
||||||
this.key_context("in_replace")
|
|
||||||
.on_action(cx.listener(Self::replace_next))
|
|
||||||
.on_action(cx.listener(Self::replace_all))
|
|
||||||
})
|
|
||||||
.on_action(cx.listener(Self::previous_history_query))
|
.on_action(cx.listener(Self::previous_history_query))
|
||||||
.on_action(cx.listener(Self::next_history_query))
|
.on_action(cx.listener(Self::next_history_query))
|
||||||
.on_action(cx.listener(Self::dismiss))
|
.on_action(cx.listener(Self::dismiss))
|
||||||
|
.on_action(cx.listener(Self::select_next_match))
|
||||||
|
.on_action(cx.listener(Self::select_prev_match))
|
||||||
|
.when(self.supported_options().replacement, |this| {
|
||||||
|
this.on_action(cx.listener(Self::toggle_replace))
|
||||||
|
.when(in_replace, |this| {
|
||||||
|
this.key_context("in_replace")
|
||||||
|
.on_action(cx.listener(Self::replace_next))
|
||||||
|
.on_action(cx.listener(Self::replace_all))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.when(self.supported_options().case, |this| {
|
||||||
|
this.on_action(cx.listener(Self::toggle_case_sensitive))
|
||||||
|
})
|
||||||
|
.when(self.supported_options().word, |this| {
|
||||||
|
this.on_action(cx.listener(Self::toggle_whole_word))
|
||||||
|
})
|
||||||
.w_full()
|
.w_full()
|
||||||
.p_1()
|
.p_1()
|
||||||
.child(
|
.child(
|
||||||
|
@ -305,7 +316,7 @@ impl BufferSearchBar {
|
||||||
|
|
||||||
let handle = cx.view().downgrade();
|
let handle = cx.view().downgrade();
|
||||||
|
|
||||||
editor.register_action(move |a: &Deploy, cx| {
|
editor.register_action(move |deploy: &Deploy, cx| {
|
||||||
let Some(pane) = handle.upgrade().and_then(|editor| editor.read(cx).pane(cx)) else {
|
let Some(pane) = handle.upgrade().and_then(|editor| editor.read(cx).pane(cx)) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
@ -313,12 +324,12 @@ impl BufferSearchBar {
|
||||||
pane.update(cx, |this, cx| {
|
pane.update(cx, |this, cx| {
|
||||||
this.toolbar().update(cx, |this, cx| {
|
this.toolbar().update(cx, |this, cx| {
|
||||||
if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
|
if let Some(search_bar) = this.item_of_type::<BufferSearchBar>() {
|
||||||
search_bar.update(cx, |this, cx| this.toggle(cx));
|
search_bar.update(cx, |this, cx| this.toggle(deploy, cx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let view = cx.build_view(|cx| BufferSearchBar::new(cx));
|
let view = cx.build_view(|cx| BufferSearchBar::new(cx));
|
||||||
this.add_item(view.clone(), cx);
|
this.add_item(view.clone(), cx);
|
||||||
view.update(cx, |this, cx| this.deploy(a, cx));
|
view.update(cx, |this, cx| this.deploy(deploy, cx));
|
||||||
cx.notify();
|
cx.notify();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -468,7 +479,7 @@ impl BufferSearchBar {
|
||||||
self.search_suggested(cx);
|
self.search_suggested(cx);
|
||||||
if deploy.focus {
|
if deploy.focus {
|
||||||
self.select_query(cx);
|
self.select_query(cx);
|
||||||
let handle = cx.focus_handle();
|
let handle = self.query_editor.focus_handle(cx);
|
||||||
cx.focus(&handle);
|
cx.focus(&handle);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -477,9 +488,9 @@ impl BufferSearchBar {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn toggle(&mut self, action: &Deploy, cx: &mut ViewContext<Self>) {
|
||||||
if self.is_dismissed() {
|
if self.is_dismissed() {
|
||||||
self.show(cx);
|
self.deploy(action, cx);
|
||||||
} else {
|
} else {
|
||||||
self.dismiss(&Dismiss, cx);
|
self.dismiss(&Dismiss, cx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue