mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-06 18:46:49 +00:00
Select query when focusing query editor
Also: Clear the selection when we focus the results editor because we continue to render the selection even when the editor isn't focused and it looks awkward. Another approach we could take is to not render selections for non-focused editors, either always or with an option. But considering that we select all anyways next time we return focus to the query editor, I think this is ok for now.
This commit is contained in:
parent
e96d0a9355
commit
28b71cbc03
1 changed files with 15 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
use crate::SearchOption;
|
||||
use editor::{Anchor, Autoscroll, Editor, MultiBuffer};
|
||||
use editor::{Anchor, Autoscroll, Editor, MultiBuffer, SelectAll};
|
||||
use gpui::{
|
||||
action, elements::*, keymap::Binding, platform::CursorStyle, AppContext, ElementBox, Entity,
|
||||
ModelContext, ModelHandle, MutableAppContext, RenderContext, Task, View, ViewContext,
|
||||
|
@ -230,7 +230,7 @@ impl View for ProjectFindView {
|
|||
if self.model.read(cx).highlighted_ranges.is_empty() {
|
||||
cx.focus(&self.query_editor);
|
||||
} else {
|
||||
cx.focus(&self.results_editor);
|
||||
self.focus_results_editor(cx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -471,13 +471,24 @@ impl ProjectFindView {
|
|||
fn toggle_focus(&mut self, _: &ToggleFocus, cx: &mut ViewContext<Self>) {
|
||||
if self.query_editor.is_focused(cx) {
|
||||
if !self.model.read(cx).highlighted_ranges.is_empty() {
|
||||
cx.focus(&self.results_editor);
|
||||
self.focus_results_editor(cx);
|
||||
}
|
||||
} else {
|
||||
self.query_editor.update(cx, |query_editor, cx| {
|
||||
query_editor.select_all(&SelectAll, cx);
|
||||
});
|
||||
cx.focus(&self.query_editor);
|
||||
}
|
||||
}
|
||||
|
||||
fn focus_results_editor(&self, cx: &mut ViewContext<Self>) {
|
||||
self.query_editor.update(cx, |query_editor, cx| {
|
||||
let head = query_editor.newest_anchor_selection().head();
|
||||
query_editor.select_ranges([head.clone()..head], None, cx);
|
||||
});
|
||||
cx.focus(&self.results_editor);
|
||||
}
|
||||
|
||||
fn model_changed(&mut self, reset_selections: bool, cx: &mut ViewContext<Self>) {
|
||||
let highlighted_ranges = self.model.read(cx).highlighted_ranges.clone();
|
||||
if !highlighted_ranges.is_empty() {
|
||||
|
@ -489,7 +500,7 @@ impl ProjectFindView {
|
|||
}
|
||||
});
|
||||
if self.query_editor.is_focused(cx) {
|
||||
cx.focus(&self.results_editor);
|
||||
self.focus_results_editor(cx);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue