Only compute placeholder text once
This commit is contained in:
parent
9acb5825e6
commit
d499cccebb
2 changed files with 48 additions and 53 deletions
|
@ -1998,6 +1998,10 @@ impl Editor {
|
||||||
self.collaboration_hub = Some(hub);
|
self.collaboration_hub = Some(hub);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn placeholder_text(&self) -> Option<&str> {
|
||||||
|
self.placeholder_text.as_deref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_placeholder_text(
|
pub fn set_placeholder_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
placeholder_text: impl Into<Arc<str>>,
|
placeholder_text: impl Into<Arc<str>>,
|
||||||
|
|
|
@ -102,66 +102,57 @@ impl EventEmitter<Event> for BufferSearchBar {}
|
||||||
impl EventEmitter<workspace::ToolbarItemEvent> for BufferSearchBar {}
|
impl EventEmitter<workspace::ToolbarItemEvent> for BufferSearchBar {}
|
||||||
impl Render for BufferSearchBar {
|
impl Render for BufferSearchBar {
|
||||||
type Element = Div;
|
type Element = Div;
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
|
||||||
// let query_container_style = if self.query_contains_error {
|
|
||||||
// theme.search.invalid_editor
|
|
||||||
// } else {
|
|
||||||
// theme.search.editor.input.container
|
|
||||||
// };
|
|
||||||
if self.dismissed {
|
if self.dismissed {
|
||||||
return div();
|
return div();
|
||||||
}
|
}
|
||||||
|
|
||||||
let supported_options = self.supported_options();
|
let supported_options = self.supported_options();
|
||||||
|
|
||||||
let query_focus_handle = self.query_editor.focus_handle(cx);
|
if self.query_editor.read(cx).placeholder_text().is_none() {
|
||||||
let previous_query_keystrokes = cx
|
let query_focus_handle = self.query_editor.focus_handle(cx);
|
||||||
.bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle)
|
let up_keystrokes = cx
|
||||||
.into_iter()
|
.bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle)
|
||||||
.next()
|
.into_iter()
|
||||||
.map(|binding| {
|
.next()
|
||||||
binding
|
.map(|binding| {
|
||||||
.keystrokes()
|
binding
|
||||||
.iter()
|
.keystrokes()
|
||||||
.map(|k| k.to_string())
|
.iter()
|
||||||
.collect::<Vec<_>>()
|
.map(|k| k.to_string())
|
||||||
});
|
.collect::<Vec<_>>()
|
||||||
let next_query_keystrokes = cx
|
});
|
||||||
.bindings_for_action_in(&NextHistoryQuery {}, &query_focus_handle)
|
let down_keystrokes = cx
|
||||||
.into_iter()
|
.bindings_for_action_in(&NextHistoryQuery {}, &query_focus_handle)
|
||||||
.next()
|
.into_iter()
|
||||||
.map(|binding| {
|
.next()
|
||||||
binding
|
.map(|binding| {
|
||||||
.keystrokes()
|
binding
|
||||||
.iter()
|
.keystrokes()
|
||||||
.map(|k| k.to_string())
|
.iter()
|
||||||
.collect::<Vec<_>>()
|
.map(|k| k.to_string())
|
||||||
});
|
.collect::<Vec<_>>()
|
||||||
let new_placeholder_text = match (previous_query_keystrokes, next_query_keystrokes) {
|
});
|
||||||
(Some(previous_query_keystrokes), Some(next_query_keystrokes)) => {
|
|
||||||
format!(
|
let placeholder_text =
|
||||||
"Search ({}/{} for previous/next query)",
|
up_keystrokes
|
||||||
previous_query_keystrokes.join(" "),
|
.zip(down_keystrokes)
|
||||||
next_query_keystrokes.join(" ")
|
.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, 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(" ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
(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| {
|
self.replacement_editor.update(cx, |editor, cx| {
|
||||||
editor.set_placeholder_text("Replace with...", cx);
|
editor.set_placeholder_text("Replace with...", cx);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue