Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Compute the query editor placeholder text with a focus handle
Nathan Sobo9acb5825e66f
diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex 58f8e857a9a..aa627db2a3b 100644--- a/crates/editor2/src/editor.rs+++ b/crates/editor2/src/editor.rs@@ -2003,8 +2003,11 @@ impl Editor {placeholder_text: impl Into<Arc<str>>,cx: &mut ViewContext<Self>,) {- self.placeholder_text = Some(placeholder_text.into());- cx.notify();+ let placeholder_text = Some(placeholder_text.into());+ if self.placeholder_text != placeholder_text {+ self.placeholder_text = placeholder_text;+ cx.notify();+ }}pub fn set_cursor_shape(&mut self, cursor_shape: CursorShape, cx: &mut ViewContext<Self>) {diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rsindex 8031bc5db60..9dab9d00aec 100644--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@ -1722,11 +1722,12 @@ impl EditorElement {return Vec::new();}- // When the editor is empty and unfocused, then show the placeholder.+ // Show the placeholder when the editor is emptyif snapshot.is_empty() {let font_size = self.style.text.font_size.to_pixels(cx.rem_size());let placeholder_color = cx.theme().styles.colors.text_placeholder;let placeholder_text = snapshot.placeholder_text();+let placeholder_lines = placeholder_text.as_ref().map_or("", AsRef::as_ref)diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rsindex ebaf111e606..f84db72c13f 100644--- a/crates/search2/src/buffer_search.rs+++ b/crates/search2/src/buffer_search.rs@@ -113,8 +113,9 @@ impl Render for BufferSearchBar {}let supported_options = self.supported_options();+ let query_focus_handle = self.query_editor.focus_handle(cx);let previous_query_keystrokes = cx- .bindings_for_action(&PreviousHistoryQuery {})+ .bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle).into_iter().next().map(|binding| {@@ -125,7 +126,7 @@ impl Render for BufferSearchBar {.collect::<Vec<_>>()});let next_query_keystrokes = cx- .bindings_for_action(&NextHistoryQuery {})+ .bindings_for_action_in(&NextHistoryQuery {}, &query_focus_handle).into_iter().next().map(|binding| {