Correctly compute placeholder text for buffer search query editor (#3749)

Rather than relying on the focused element, instead explicitly pass the
focus handle for the query editor when determining the prev/next
bindings. Only compute these values once.

Release Notes:

- N/A
This commit is contained in:
Nathan Sobo
2023-12-20 20:48:31 -07:00
committed by GitHub
3 changed files with 55 additions and 55 deletions
+9 -2
View File
@@ -1995,13 +1995,20 @@ impl Editor {
self.collaboration_hub = Some(hub);
}
pub fn placeholder_text(&self) -> Option<&str> {
self.placeholder_text.as_deref()
}
pub fn set_placeholder_text(
&mut self,
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>) {
+2 -1
View File
@@ -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 empty
if 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)