From 7a8765a01634a97b702b2373c56fa4e36bdacc44 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 4 Feb 2022 16:11:48 +0100 Subject: [PATCH 1/2] Dismiss the focused find bar on `escape` Co-Authored-By: Nathan Sobo --- crates/find/src/find.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/find/src/find.rs b/crates/find/src/find.rs index 3de2234da1..709f37554a 100644 --- a/crates/find/src/find.rs +++ b/crates/find/src/find.rs @@ -328,10 +328,10 @@ impl FindBar { }); } - fn dismiss(workspace: &mut Workspace, _: &Dismiss, cx: &mut ViewContext) { - workspace - .active_pane() - .update(cx, |pane, cx| pane.dismiss_toolbar(cx)); + fn dismiss(pane: &mut Pane, _: &Dismiss, cx: &mut ViewContext) { + if pane.toolbar::().is_some() { + pane.dismiss_toolbar(cx); + } } fn focus_editor(&mut self, _: &FocusEditor, cx: &mut ViewContext) { From 807049af51fe2b2f234db988bb7fdf3a51af2902 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Fri, 4 Feb 2022 16:13:58 +0100 Subject: [PATCH 2/2] Always populate find bar on `cmd-f` Co-Authored-By: Nathan Sobo --- crates/find/src/find.rs | 64 ++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/crates/find/src/find.rs b/crates/find/src/find.rs index 709f37554a..8844f2cf90 100644 --- a/crates/find/src/find.rs +++ b/crates/find/src/find.rs @@ -274,54 +274,46 @@ impl FindBar { fn deploy(workspace: &mut Workspace, Deploy(focus): &Deploy, cx: &mut ViewContext) { let settings = workspace.settings(); workspace.active_pane().update(cx, |pane, cx| { - let findbar_was_visible = pane - .active_toolbar() - .map_or(false, |toolbar| toolbar.downcast::().is_some()); - pane.show_toolbar(cx, |cx| FindBar::new(settings, cx)); if let Some(find_bar) = pane .active_toolbar() .and_then(|toolbar| toolbar.downcast::()) { - if !findbar_was_visible { - let editor = pane.active_item().unwrap().act_as::(cx).unwrap(); - let display_map = editor - .update(cx, |editor, cx| editor.snapshot(cx)) - .display_snapshot; - let selection = editor - .read(cx) - .newest_selection::(&display_map.buffer_snapshot); + let editor = pane.active_item().unwrap().act_as::(cx).unwrap(); + let display_map = editor + .update(cx, |editor, cx| editor.snapshot(cx)) + .display_snapshot; + let selection = editor + .read(cx) + .newest_selection::(&display_map.buffer_snapshot); - let mut text: String; - if selection.start == selection.end { - let point = selection.start.to_display_point(&display_map); - let range = editor::movement::surrounding_word(&display_map, point); - let range = range.start.to_offset(&display_map, Bias::Left) - ..range.end.to_offset(&display_map, Bias::Right); - text = display_map.buffer_snapshot.text_for_range(range).collect(); - if text.trim().is_empty() { - text = String::new(); - } - } else { - text = display_map - .buffer_snapshot - .text_for_range(selection.start..selection.end) - .collect(); + let mut text: String; + if selection.start == selection.end { + let point = selection.start.to_display_point(&display_map); + let range = editor::movement::surrounding_word(&display_map, point); + let range = range.start.to_offset(&display_map, Bias::Left) + ..range.end.to_offset(&display_map, Bias::Right); + text = display_map.buffer_snapshot.text_for_range(range).collect(); + if text.trim().is_empty() { + text = String::new(); } + } else { + text = display_map + .buffer_snapshot + .text_for_range(selection.start..selection.end) + .collect(); + } - if !text.is_empty() { - find_bar.update(cx, |find_bar, cx| find_bar.set_query(&text, cx)); - } + if !text.is_empty() { + find_bar.update(cx, |find_bar, cx| find_bar.set_query(&text, cx)); } if *focus { - if !findbar_was_visible { - let query_editor = find_bar.read(cx).query_editor.clone(); - query_editor.update(cx, |query_editor, cx| { - query_editor.select_all(&editor::SelectAll, cx); - }); - } + let query_editor = find_bar.read(cx).query_editor.clone(); + query_editor.update(cx, |query_editor, cx| { + query_editor.select_all(&editor::SelectAll, cx); + }); cx.focus(&find_bar); } }