mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-11 21:13:02 +00:00
Always populate find bar on cmd-f
Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
7a8765a016
commit
807049af51
1 changed files with 28 additions and 36 deletions
|
@ -274,54 +274,46 @@ impl FindBar {
|
||||||
fn deploy(workspace: &mut Workspace, Deploy(focus): &Deploy, cx: &mut ViewContext<Workspace>) {
|
fn deploy(workspace: &mut Workspace, Deploy(focus): &Deploy, cx: &mut ViewContext<Workspace>) {
|
||||||
let settings = workspace.settings();
|
let settings = workspace.settings();
|
||||||
workspace.active_pane().update(cx, |pane, cx| {
|
workspace.active_pane().update(cx, |pane, cx| {
|
||||||
let findbar_was_visible = pane
|
|
||||||
.active_toolbar()
|
|
||||||
.map_or(false, |toolbar| toolbar.downcast::<Self>().is_some());
|
|
||||||
|
|
||||||
pane.show_toolbar(cx, |cx| FindBar::new(settings, cx));
|
pane.show_toolbar(cx, |cx| FindBar::new(settings, cx));
|
||||||
|
|
||||||
if let Some(find_bar) = pane
|
if let Some(find_bar) = pane
|
||||||
.active_toolbar()
|
.active_toolbar()
|
||||||
.and_then(|toolbar| toolbar.downcast::<Self>())
|
.and_then(|toolbar| toolbar.downcast::<Self>())
|
||||||
{
|
{
|
||||||
if !findbar_was_visible {
|
let editor = pane.active_item().unwrap().act_as::<Editor>(cx).unwrap();
|
||||||
let editor = pane.active_item().unwrap().act_as::<Editor>(cx).unwrap();
|
let display_map = editor
|
||||||
let display_map = editor
|
.update(cx, |editor, cx| editor.snapshot(cx))
|
||||||
.update(cx, |editor, cx| editor.snapshot(cx))
|
.display_snapshot;
|
||||||
.display_snapshot;
|
let selection = editor
|
||||||
let selection = editor
|
.read(cx)
|
||||||
.read(cx)
|
.newest_selection::<usize>(&display_map.buffer_snapshot);
|
||||||
.newest_selection::<usize>(&display_map.buffer_snapshot);
|
|
||||||
|
|
||||||
let mut text: String;
|
let mut text: String;
|
||||||
if selection.start == selection.end {
|
if selection.start == selection.end {
|
||||||
let point = selection.start.to_display_point(&display_map);
|
let point = selection.start.to_display_point(&display_map);
|
||||||
let range = editor::movement::surrounding_word(&display_map, point);
|
let range = editor::movement::surrounding_word(&display_map, point);
|
||||||
let range = range.start.to_offset(&display_map, Bias::Left)
|
let range = range.start.to_offset(&display_map, Bias::Left)
|
||||||
..range.end.to_offset(&display_map, Bias::Right);
|
..range.end.to_offset(&display_map, Bias::Right);
|
||||||
text = display_map.buffer_snapshot.text_for_range(range).collect();
|
text = display_map.buffer_snapshot.text_for_range(range).collect();
|
||||||
if text.trim().is_empty() {
|
if text.trim().is_empty() {
|
||||||
text = String::new();
|
text = String::new();
|
||||||
}
|
|
||||||
} else {
|
|
||||||
text = display_map
|
|
||||||
.buffer_snapshot
|
|
||||||
.text_for_range(selection.start..selection.end)
|
|
||||||
.collect();
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
text = display_map
|
||||||
|
.buffer_snapshot
|
||||||
|
.text_for_range(selection.start..selection.end)
|
||||||
|
.collect();
|
||||||
|
}
|
||||||
|
|
||||||
if !text.is_empty() {
|
if !text.is_empty() {
|
||||||
find_bar.update(cx, |find_bar, cx| find_bar.set_query(&text, cx));
|
find_bar.update(cx, |find_bar, cx| find_bar.set_query(&text, cx));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if *focus {
|
if *focus {
|
||||||
if !findbar_was_visible {
|
let query_editor = find_bar.read(cx).query_editor.clone();
|
||||||
let query_editor = find_bar.read(cx).query_editor.clone();
|
query_editor.update(cx, |query_editor, cx| {
|
||||||
query_editor.update(cx, |query_editor, cx| {
|
query_editor.select_all(&editor::SelectAll, cx);
|
||||||
query_editor.select_all(&editor::SelectAll, cx);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
cx.focus(&find_bar);
|
cx.focus(&find_bar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue