Allow using context in the placeholder_text method

This commit is contained in:
Kirill Bulatov 2024-02-24 23:26:40 +02:00 committed by Kirill Bulatov
parent cf3b875922
commit c29ea9bdbc
17 changed files with 24 additions and 22 deletions

View file

@ -266,7 +266,7 @@ pub struct ChannelModalDelegate {
impl PickerDelegate for ChannelModalDelegate { impl PickerDelegate for ChannelModalDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Search collaborator by username...".into() "Search collaborator by username...".into()
} }

View file

@ -84,7 +84,7 @@ impl PickerDelegate for ContactFinderDelegate {
self.selected_index = ix; self.selected_index = ix;
} }
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Search collaborator by username...".into() "Search collaborator by username...".into()
} }

View file

@ -231,7 +231,7 @@ impl CommandPaletteDelegate {
impl PickerDelegate for CommandPaletteDelegate { impl PickerDelegate for CommandPaletteDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Execute a command...".into() "Execute a command...".into()
} }

View file

@ -1749,7 +1749,7 @@ impl Editor {
self.completion_provider = Some(hub); 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() self.placeholder_text.as_deref()
} }
@ -9618,7 +9618,7 @@ impl EditorSnapshot {
self.is_focused 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() self.placeholder_text.as_ref()
} }

View file

@ -1904,7 +1904,7 @@ impl EditorElement {
rows: Range<u32>, rows: Range<u32>,
line_number_layouts: &[Option<ShapedLine>], line_number_layouts: &[Option<ShapedLine>],
snapshot: &EditorSnapshot, snapshot: &EditorSnapshot,
cx: &ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> Vec<LineWithInvisibles> { ) -> Vec<LineWithInvisibles> {
if rows.start >= rows.end { if rows.start >= rows.end {
return Vec::new(); return Vec::new();
@ -1914,7 +1914,7 @@ impl EditorElement {
if snapshot.is_empty() { if snapshot.is_empty() {
let font_size = self.style.text.font_size.to_pixels(cx.rem_size()); let font_size = self.style.text.font_size.to_pixels(cx.rem_size());
let placeholder_color = cx.theme().colors().text_placeholder; 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 let placeholder_lines = placeholder_text
.as_ref() .as_ref()

View file

@ -663,7 +663,7 @@ impl FileFinderDelegate {
impl PickerDelegate for FileFinderDelegate { impl PickerDelegate for FileFinderDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Search project files...".into() "Search project files...".into()
} }

View file

@ -120,7 +120,7 @@ impl LanguageSelectorDelegate {
impl PickerDelegate for LanguageSelectorDelegate { impl PickerDelegate for LanguageSelectorDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Select a language...".into() "Select a language...".into()
} }

View file

@ -157,7 +157,7 @@ impl OutlineViewDelegate {
impl PickerDelegate for OutlineViewDelegate { impl PickerDelegate for OutlineViewDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Search buffer symbols...".into() "Search buffer symbols...".into()
} }

View file

@ -37,7 +37,7 @@ pub trait PickerDelegate: Sized + 'static {
} }
fn set_selected_index(&mut self, ix: usize, cx: &mut ViewContext<Picker<Self>>); 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<()>; 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 // 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 { 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(); cx.subscribe(&editor, Self::on_input_editor_event).detach();
let mut this = Self { let mut this = Self {
delegate, delegate,

View file

@ -2,7 +2,7 @@ use editor::{scroll::Autoscroll, styled_runs_for_code_label, Bias, Editor};
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, rems, AppContext, DismissEvent, FontWeight, Model, ParentElement, StyledText, Task, actions, rems, AppContext, DismissEvent, FontWeight, Model, ParentElement, StyledText, Task,
View, ViewContext, WeakView, View, ViewContext, WeakView, WindowContext,
}; };
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
@ -106,7 +106,7 @@ impl ProjectSymbolsDelegate {
impl PickerDelegate for ProjectSymbolsDelegate { impl PickerDelegate for ProjectSymbolsDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Search project symbols...".into() "Search project symbols...".into()
} }

View file

@ -146,7 +146,7 @@ impl EventEmitter<DismissEvent> for RecentProjectsDelegate {}
impl PickerDelegate for RecentProjectsDelegate { impl PickerDelegate for RecentProjectsDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
Arc::from(format!( Arc::from(format!(
"`{:?}` reuses the window, `{:?}` opens in new", "`{:?}` reuses the window, `{:?}` opens in new",
menu::Confirm, menu::Confirm,

View file

@ -127,7 +127,9 @@ impl Render for BufferSearchBar {
let supported_options = self.supported_options(); 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 query_focus_handle = self.query_editor.focus_handle(cx);
let up_keystrokes = cx let up_keystrokes = cx
.bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle) .bindings_for_action_in(&PreviousHistoryQuery {}, &query_focus_handle)

View file

@ -41,7 +41,7 @@ impl PickerDelegate for Delegate {
self.candidates.len() self.candidates.len()
} }
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Test".into() "Test".into()
} }

View file

@ -9,7 +9,7 @@ use gpui::{
use picker::{Picker, PickerDelegate}; use picker::{Picker, PickerDelegate};
use project::Inventory; use project::Inventory;
use task::{oneshot_source::OneshotSource, Task}; 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 util::ResultExt;
use workspace::{ModalView, Workspace}; use workspace::{ModalView, Workspace};
@ -115,7 +115,7 @@ impl PickerDelegate for TasksModalDelegate {
self.selected_index = ix; self.selected_index = ix;
} }
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
self.placeholder_text.clone() self.placeholder_text.clone()
} }

View file

@ -153,7 +153,7 @@ impl ThemeSelectorDelegate {
impl PickerDelegate for ThemeSelectorDelegate { impl PickerDelegate for ThemeSelectorDelegate {
type ListItem = ui::ListItem; type ListItem = ui::ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Select Theme...".into() "Select Theme...".into()
} }

View file

@ -135,7 +135,7 @@ impl BranchListDelegate {
impl PickerDelegate for BranchListDelegate { impl PickerDelegate for BranchListDelegate {
type ListItem = ListItem; type ListItem = ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Select branch...".into() "Select branch...".into()
} }

View file

@ -99,7 +99,7 @@ impl BaseKeymapSelectorDelegate {
impl PickerDelegate for BaseKeymapSelectorDelegate { impl PickerDelegate for BaseKeymapSelectorDelegate {
type ListItem = ui::ListItem; type ListItem = ui::ListItem;
fn placeholder_text(&self) -> Arc<str> { fn placeholder_text(&self, _cx: &mut WindowContext) -> Arc<str> {
"Select a base keymap...".into() "Select a base keymap...".into()
} }