From c29ea9bdbcab0a4c40d30c1e74bd6d81fdbadde1 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 24 Feb 2024 23:26:40 +0200 Subject: [PATCH] Allow using context in the `placeholder_text` method --- crates/collab_ui/src/collab_panel/channel_modal.rs | 2 +- crates/collab_ui/src/collab_panel/contact_finder.rs | 2 +- crates/command_palette/src/command_palette.rs | 2 +- crates/editor/src/editor.rs | 4 ++-- crates/editor/src/element.rs | 4 ++-- crates/file_finder/src/file_finder.rs | 2 +- crates/language_selector/src/language_selector.rs | 2 +- crates/outline/src/outline.rs | 2 +- crates/picker/src/picker.rs | 4 ++-- crates/project_symbols/src/project_symbols.rs | 4 ++-- crates/recent_projects/src/recent_projects.rs | 2 +- crates/search/src/buffer_search.rs | 4 +++- crates/storybook/src/stories/picker.rs | 2 +- crates/tasks_ui/src/modal.rs | 4 ++-- crates/theme_selector/src/theme_selector.rs | 2 +- crates/vcs_menu/src/lib.rs | 2 +- crates/welcome/src/base_keymap_picker.rs | 2 +- 17 files changed, 24 insertions(+), 22 deletions(-) diff --git a/crates/collab_ui/src/collab_panel/channel_modal.rs b/crates/collab_ui/src/collab_panel/channel_modal.rs index 501524501e..54e564590e 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "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.rs index 6a1932a843..ff58c833f1 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Search collaborator by username...".into() } diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs index e7edf393ff..98dd3bcf75 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Execute a command...".into() } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 0bcf55468e..f32273b6e3 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> { + pub fn placeholder_text(&self, _cx: &mut WindowContext) -> Option<&Arc> { self.placeholder_text.as_ref() } diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 099c52d7fd..654b8be4b6 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -1904,7 +1904,7 @@ impl EditorElement { rows: Range, line_number_layouts: &[Option], snapshot: &EditorSnapshot, - cx: &ViewContext, + cx: &mut ViewContext, ) -> Vec { 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.rs index fc8e5d1d99..eb57afece1 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Search project files...".into() } diff --git a/crates/language_selector/src/language_selector.rs b/crates/language_selector/src/language_selector.rs index 0a3faffbee..6bdf5a67d0 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Select a language...".into() } diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rs index a078ad6a7c..627c4a0de2 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Search buffer symbols...".into() } diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 1ade6eed1f..55ee340035 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>); - fn placeholder_text(&self) -> Arc; + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc; fn update_matches(&mut self, query: String, cx: &mut ViewContext>) -> Task<()>; // Delegates that support this method (e.g. the CommandPalette) can chose to block on any background @@ -98,7 +98,7 @@ impl Picker { } fn new(delegate: D, cx: &mut ViewContext, 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.rs index bd5b2e64c4..61cc7059a6 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Search project symbols...".into() } diff --git a/crates/recent_projects/src/recent_projects.rs b/crates/recent_projects/src/recent_projects.rs index db4e73d6b2..314eccccac 100644 --- a/crates/recent_projects/src/recent_projects.rs +++ b/crates/recent_projects/src/recent_projects.rs @@ -146,7 +146,7 @@ impl EventEmitter for RecentProjectsDelegate {} impl PickerDelegate for RecentProjectsDelegate { type ListItem = ListItem; - fn placeholder_text(&self) -> Arc { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { 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.rs index 597e8a4797..84da37155c 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.rs index cdc0a0907e..5d4c8dfc89 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Test".into() } diff --git a/crates/tasks_ui/src/modal.rs b/crates/tasks_ui/src/modal.rs index de5cc5d596..47724f80b9 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { self.placeholder_text.clone() } diff --git a/crates/theme_selector/src/theme_selector.rs b/crates/theme_selector/src/theme_selector.rs index 2ad1085f66..c0008e90d6 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Select Theme...".into() } diff --git a/crates/vcs_menu/src/lib.rs b/crates/vcs_menu/src/lib.rs index 645c3e7128..55cfcda944 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Select branch...".into() } diff --git a/crates/welcome/src/base_keymap_picker.rs b/crates/welcome/src/base_keymap_picker.rs index c6acd95a96..aa65051c0b 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 { + fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc { "Select a base keymap...".into() }