diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index aa627db2a3baa08764f8d8569c65a9cee638ffed..cb607a7e6c16a23b6294907ce1715e3ad9e75513 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -1998,6 +1998,10 @@ 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>, diff --git a/crates/search2/src/buffer_search.rs b/crates/search2/src/buffer_search.rs index f84db72c13f224e7fdcb56f7b78a7f6d193f6370..5b4113aee2eef1a9e7b602e74f0479e23df4bdf4 100644 --- a/crates/search2/src/buffer_search.rs +++ b/crates/search2/src/buffer_search.rs @@ -102,66 +102,57 @@ impl EventEmitter for BufferSearchBar {} impl EventEmitter for BufferSearchBar {} impl Render for BufferSearchBar { type Element = Div; + fn render(&mut self, cx: &mut ViewContext) -> Self::Element { - // let query_container_style = if self.query_contains_error { - // theme.search.invalid_editor - // } else { - // theme.search.editor.input.container - // }; if self.dismissed { return div(); } + let supported_options = self.supported_options(); - let query_focus_handle = self.query_editor.focus_handle(cx); - let previous_query_keystrokes = cx - .bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle) - .into_iter() - .next() - .map(|binding| { - binding - .keystrokes() - .iter() - .map(|k| k.to_string()) - .collect::>() - }); - let next_query_keystrokes = cx - .bindings_for_action_in(&NextHistoryQuery {}, &query_focus_handle) - .into_iter() - .next() - .map(|binding| { - binding - .keystrokes() - .iter() - .map(|k| k.to_string()) - .collect::>() - }); - let new_placeholder_text = match (previous_query_keystrokes, next_query_keystrokes) { - (Some(previous_query_keystrokes), Some(next_query_keystrokes)) => { - format!( - "Search ({}/{} for previous/next query)", - previous_query_keystrokes.join(" "), - next_query_keystrokes.join(" ") - ) - } - (None, Some(next_query_keystrokes)) => { - format!( - "Search ({} for next query)", - next_query_keystrokes.join(" ") - ) - } - (Some(previous_query_keystrokes), None) => { - format!( - "Search ({} for previous query)", - previous_query_keystrokes.join(" ") - ) + if self.query_editor.read(cx).placeholder_text().is_none() { + let query_focus_handle = self.query_editor.focus_handle(cx); + let up_keystrokes = cx + .bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle) + .into_iter() + .next() + .map(|binding| { + binding + .keystrokes() + .iter() + .map(|k| k.to_string()) + .collect::>() + }); + let down_keystrokes = cx + .bindings_for_action_in(&NextHistoryQuery {}, &query_focus_handle) + .into_iter() + .next() + .map(|binding| { + binding + .keystrokes() + .iter() + .map(|k| k.to_string()) + .collect::>() + }); + + let placeholder_text = + up_keystrokes + .zip(down_keystrokes) + .map(|(up_keystrokes, down_keystrokes)| { + Arc::from(format!( + "Search ({}/{} for previous/next query)", + up_keystrokes.join(" "), + down_keystrokes.join(" ") + )) + }); + + if let Some(placeholder_text) = placeholder_text { + self.query_editor.update(cx, |editor, cx| { + editor.set_placeholder_text(placeholder_text, cx); + }); } - (None, None) => String::new(), - }; - let new_placeholder_text = Arc::from(new_placeholder_text); - self.query_editor.update(cx, |editor, cx| { - editor.set_placeholder_text(new_placeholder_text, cx); - }); + } + self.replacement_editor.update(cx, |editor, cx| { editor.set_placeholder_text("Replace with...", cx); });