Merge pull request #795 from zed-industries/cancel-buffer-search
Handle editor cancel in pane in order to dismiss find toolbar
This commit is contained in:
commit
54d49c13d9
2 changed files with 36 additions and 21 deletions
|
@ -1700,33 +1700,37 @@ impl Editor {
|
|||
return;
|
||||
}
|
||||
|
||||
if self.mode != EditorMode::Full {
|
||||
cx.propagate_action();
|
||||
return;
|
||||
}
|
||||
|
||||
if self.active_diagnostics.is_some() {
|
||||
self.dismiss_diagnostics(cx);
|
||||
} else if let Some(pending) = self.pending_selection.clone() {
|
||||
let mut selections = self.selections.clone();
|
||||
if selections.is_empty() {
|
||||
selections = Arc::from([pending.selection]);
|
||||
if self.mode == EditorMode::Full {
|
||||
if self.active_diagnostics.is_some() {
|
||||
self.dismiss_diagnostics(cx);
|
||||
return;
|
||||
}
|
||||
self.set_selections(selections, None, true, cx);
|
||||
self.request_autoscroll(Autoscroll::Fit, cx);
|
||||
} else {
|
||||
let mut oldest_selection = self.oldest_selection::<usize>(&cx);
|
||||
if self.selection_count() == 1 {
|
||||
if oldest_selection.is_empty() {
|
||||
cx.propagate_action();
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(pending) = self.pending_selection.clone() {
|
||||
let mut selections = self.selections.clone();
|
||||
if selections.is_empty() {
|
||||
selections = Arc::from([pending.selection]);
|
||||
}
|
||||
self.set_selections(selections, None, true, cx);
|
||||
self.request_autoscroll(Autoscroll::Fit, cx);
|
||||
return;
|
||||
}
|
||||
|
||||
let mut oldest_selection = self.oldest_selection::<usize>(&cx);
|
||||
if self.selection_count() > 1 {
|
||||
self.update_selections(vec![oldest_selection], Some(Autoscroll::Fit), cx);
|
||||
return;
|
||||
}
|
||||
|
||||
if !oldest_selection.is_empty() {
|
||||
oldest_selection.start = oldest_selection.head().clone();
|
||||
oldest_selection.end = oldest_selection.head().clone();
|
||||
self.update_selections(vec![oldest_selection], Some(Autoscroll::Fit), cx);
|
||||
return;
|
||||
}
|
||||
self.update_selections(vec![oldest_selection], Some(Autoscroll::Fit), cx);
|
||||
}
|
||||
|
||||
cx.propagate_action();
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
|
|
|
@ -41,6 +41,7 @@ pub fn init(cx: &mut MutableAppContext) {
|
|||
cx.add_action(BufferSearchBar::select_prev_match);
|
||||
cx.add_action(BufferSearchBar::select_next_match_on_pane);
|
||||
cx.add_action(BufferSearchBar::select_prev_match_on_pane);
|
||||
cx.add_action(BufferSearchBar::handle_editor_cancel);
|
||||
}
|
||||
|
||||
pub struct BufferSearchBar {
|
||||
|
@ -333,6 +334,16 @@ impl BufferSearchBar {
|
|||
cx.propagate_action();
|
||||
}
|
||||
|
||||
fn handle_editor_cancel(pane: &mut Pane, _: &editor::Cancel, cx: &mut ViewContext<Pane>) {
|
||||
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
||||
if !search_bar.read(cx).dismissed {
|
||||
search_bar.update(cx, |search_bar, cx| search_bar.dismiss(&Dismiss, cx));
|
||||
return;
|
||||
}
|
||||
}
|
||||
cx.propagate_action();
|
||||
}
|
||||
|
||||
fn focus_editor(&mut self, _: &FocusEditor, cx: &mut ViewContext<Self>) {
|
||||
if let Some(active_editor) = self.active_editor.as_ref() {
|
||||
cx.focus(active_editor);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue