Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Allow using context in the `placeholder_text` method
Kirill Bulatovc29ea9bdbcab
diff --git a/crates/collab_ui/src/collab_panel/channel_modal.rs b/crates/collab_ui/src/collab_panel/channel_modal.rsindex 501524501e6..54e564590e2 100644--- a/crates/collab_ui/src/collab_panel/channel_modal.rs+++ b/crates/collab_ui/src/collab_panel/channel_modal.rs@@ -266,7 +266,7 @@ pub struct ChannelModalDelegate {impl PickerDelegate for ChannelModalDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Search collaborator by username...".into()}diff --git a/crates/collab_ui/src/collab_panel/contact_finder.rs b/crates/collab_ui/src/collab_panel/contact_finder.rsindex 6a1932a843b..ff58c833f13 100644--- a/crates/collab_ui/src/collab_panel/contact_finder.rs+++ b/crates/collab_ui/src/collab_panel/contact_finder.rs@@ -84,7 +84,7 @@ impl PickerDelegate for ContactFinderDelegate {self.selected_index = ix;}- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Search collaborator by username...".into()}diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rsindex e7edf393ffa..98dd3bcf751 100644--- a/crates/command_palette/src/command_palette.rs+++ b/crates/command_palette/src/command_palette.rs@@ -231,7 +231,7 @@ impl CommandPaletteDelegate {impl PickerDelegate for CommandPaletteDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Execute a command...".into()}diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 0bcf55468e5..f32273b6e37 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -1749,7 +1749,7 @@ impl Editor {self.completion_provider = Some(hub);}- pub fn placeholder_text(&self) -> Option<&str> {+ pub fn placeholder_text(&self, _cx: &mut WindowContext) -> Option<&str> {self.placeholder_text.as_deref()}@@ -9618,7 +9618,7 @@ impl EditorSnapshot {self.is_focused}- pub fn placeholder_text(&self) -> Option<&Arc<str>> {+ pub fn placeholder_text(&self, _cx: &mut WindowContext) -> Option<&Arc<str>> {self.placeholder_text.as_ref()}diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 099c52d7fd3..654b8be4b6e 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -1904,7 +1904,7 @@ impl EditorElement {rows: Range<u32>,line_number_layouts: &[Option<ShapedLine>],snapshot: &EditorSnapshot,- cx: &ViewContext<Editor>,+ cx: &mut ViewContext<Editor>,) -> Vec<LineWithInvisibles> {if rows.start >= rows.end {return Vec::new();@@ -1914,7 +1914,7 @@ impl EditorElement {if snapshot.is_empty() {let font_size = self.style.text.font_size.to_pixels(cx.rem_size());let placeholder_color = cx.theme().colors().text_placeholder;- let placeholder_text = snapshot.placeholder_text();+ let placeholder_text = snapshot.placeholder_text(cx);let placeholder_lines = placeholder_text.as_ref()diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rsindex fc8e5d1d995..eb57afece18 100644--- a/crates/file_finder/src/file_finder.rs+++ b/crates/file_finder/src/file_finder.rs@@ -663,7 +663,7 @@ impl FileFinderDelegate {impl PickerDelegate for FileFinderDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Search project files...".into()}diff --git a/crates/language_selector/src/language_selector.rs b/crates/language_selector/src/language_selector.rsindex 0a3faffbeee..6bdf5a67d00 100644--- a/crates/language_selector/src/language_selector.rs+++ b/crates/language_selector/src/language_selector.rs@@ -120,7 +120,7 @@ impl LanguageSelectorDelegate {impl PickerDelegate for LanguageSelectorDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Select a language...".into()}diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rsindex a078ad6a7c0..627c4a0de24 100644--- a/crates/outline/src/outline.rs+++ b/crates/outline/src/outline.rs@@ -157,7 +157,7 @@ impl OutlineViewDelegate {impl PickerDelegate for OutlineViewDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Search buffer symbols...".into()}diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rsindex 1ade6eed1f5..55ee3400359 100644--- a/crates/picker/src/picker.rs+++ b/crates/picker/src/picker.rs@@ -37,7 +37,7 @@ pub trait PickerDelegate: Sized + 'static {}fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>);- fn placeholder_text(&self) -> Arc<str>;+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str>;fn update_matches(&mut self, query: String, cx: &mut ViewContext<Picker<Self>>) -> Task<()>;// Delegates that support this method (e.g. the CommandPalette) can chose to block on any background@@ -98,7 +98,7 @@ impl<D: PickerDelegate> Picker<D> {}fn new(delegate: D, cx: &mut ViewContext<Self>, is_uniform: bool) -> Self {- let editor = create_editor(delegate.placeholder_text(), cx);+ let editor = create_editor(delegate.placeholder_text(cx), cx);cx.subscribe(&editor, Self::on_input_editor_event).detach();let mut this = Self {delegate,diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rsindex bd5b2e64c4a..61cc7059a64 100644--- a/crates/project_symbols/src/project_symbols.rs+++ b/crates/project_symbols/src/project_symbols.rs@@ -2,7 +2,7 @@ use editor::{scroll::Autoscroll, styled_runs_for_code_label, Bias, Editor};use fuzzy::{StringMatch, StringMatchCandidate};use gpui::{actions, rems, AppContext, DismissEvent, FontWeight, Model, ParentElement, StyledText, Task,- View, ViewContext, WeakView,+ View, ViewContext, WeakView, WindowContext,};use ordered_float::OrderedFloat;use picker::{Picker, PickerDelegate};@@ -106,7 +106,7 @@ impl ProjectSymbolsDelegate {impl PickerDelegate for ProjectSymbolsDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Search project symbols...".into()}diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rsindex db4e73d6b20..314eccccaca 100644--- a/crates/recent_projects/src/recent_projects.rs+++ b/crates/recent_projects/src/recent_projects.rs@@ -146,7 +146,7 @@ impl EventEmitter<DismissEvent> for RecentProjectsDelegate {}impl PickerDelegate for RecentProjectsDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {Arc::from(format!("`{:?}` reuses the window, `{:?}` opens in new",menu::Confirm,diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rsindex 597e8a47972..84da37155c0 100644--- a/crates/search/src/buffer_search.rs+++ b/crates/search/src/buffer_search.rs@@ -127,7 +127,9 @@ impl Render for BufferSearchBar {let supported_options = self.supported_options();- if self.query_editor.read(cx).placeholder_text().is_none() {+ if self.query_editor.update(cx, |query_editor, cx| {+ query_editor.placeholder_text(cx).is_none()+ }) {let query_focus_handle = self.query_editor.focus_handle(cx);let up_keystrokes = cx.bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle)diff --git a/crates/storybook/src/stories/picker.rs b/crates/storybook/src/stories/picker.rsindex cdc0a0907ed..5d4c8dfc897 100644--- a/crates/storybook/src/stories/picker.rs+++ b/crates/storybook/src/stories/picker.rs@@ -41,7 +41,7 @@ impl PickerDelegate for Delegate {self.candidates.len()}- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Test".into()}diff --git a/crates/tasks_ui/src/modal.rs b/crates/tasks_ui/src/modal.rsindex de5cc5d5968..47724f80b92 100644--- a/crates/tasks_ui/src/modal.rs+++ b/crates/tasks_ui/src/modal.rs@@ -9,7 +9,7 @@ use gpui::{use picker::{Picker, PickerDelegate};use project::Inventory;use task::{oneshot_source::OneshotSource, Task};-use ui::{v_flex, HighlightedLabel, ListItem, ListItemSpacing, Selectable};+use ui::{v_flex, HighlightedLabel, ListItem, ListItemSpacing, Selectable, WindowContext};use util::ResultExt;use workspace::{ModalView, Workspace};@@ -115,7 +115,7 @@ impl PickerDelegate for TasksModalDelegate {self.selected_index = ix;}- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {self.placeholder_text.clone()}diff --git a/crates/theme_selector/src/theme_selector.rs b/crates/theme_selector/src/theme_selector.rsindex 2ad1085f66c..c0008e90d6c 100644--- a/crates/theme_selector/src/theme_selector.rs+++ b/crates/theme_selector/src/theme_selector.rs@@ -153,7 +153,7 @@ impl ThemeSelectorDelegate {impl PickerDelegate for ThemeSelectorDelegate {type ListItem = ui::ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Select Theme...".into()}diff --git a/crates/vcs_menu/src/lib.rs b/crates/vcs_menu/src/lib.rsindex 645c3e71282..55cfcda9442 100644--- a/crates/vcs_menu/src/lib.rs+++ b/crates/vcs_menu/src/lib.rs@@ -135,7 +135,7 @@ impl BranchListDelegate {impl PickerDelegate for BranchListDelegate {type ListItem = ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Select branch...".into()}diff --git a/crates/welcome/src/base_keymap_picker.rs b/crates/welcome/src/base_keymap_picker.rsindex c6acd95a961..aa65051c0b4 100644--- a/crates/welcome/src/base_keymap_picker.rs+++ b/crates/welcome/src/base_keymap_picker.rs@@ -99,7 +99,7 @@ impl BaseKeymapSelectorDelegate {impl PickerDelegate for BaseKeymapSelectorDelegate {type ListItem = ui::ListItem;- fn placeholder_text(&self) -> Arc<str> {+ fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {"Select a base keymap...".into()}