Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Implement `Selectable` for `ListItem` and `ListHeader`

Marshall Bowerse78538e16298
diff --git a/crates/command_palette2/src/command_palette.rs b/crates/command_palette2/src/command_palette.rs
index f9b58b1d561..04688b05492 100644
--- a/crates/command_palette2/src/command_palette.rs
+++ b/crates/command_palette2/src/command_palette.rs
@@ -11,7 +11,7 @@ use gpui::{
};
use picker::{Picker, PickerDelegate};
-use ui::{h_stack, v_stack, HighlightedLabel, KeyBinding, ListItem};
+use ui::{h_stack, prelude::*, v_stack, HighlightedLabel, KeyBinding, ListItem};
use util::{
channel::{parse_zed_link, ReleaseChannel, RELEASE_CHANNEL},
ResultExt,
diff --git a/crates/file_finder2/src/file_finder.rs b/crates/file_finder2/src/file_finder.rs
index 7a00b2644a5..ea00c5a635d 100644
--- a/crates/file_finder2/src/file_finder.rs
+++ b/crates/file_finder2/src/file_finder.rs
@@ -15,7 +15,7 @@ use std::{
},
};
use text::Point;
-use ui::{v_stack, HighlightedLabel, ListItem};
+use ui::{prelude::*, v_stack, HighlightedLabel, ListItem};
use util::{paths::PathLikeWithPosition, post_inc, ResultExt};
use workspace::Workspace;
diff --git a/crates/project_panel2/src/project_panel.rs b/crates/project_panel2/src/project_panel.rs
index dc584d52ff5..fd0473358e5 100644
--- a/crates/project_panel2/src/project_panel.rs
+++ b/crates/project_panel2/src/project_panel.rs
@@ -29,8 +29,7 @@ use std::{
path::Path,
sync::Arc,
};
-use theme::ActiveTheme as _;
-use ui::{v_stack, ContextMenu, IconElement, Label, ListItem};
+use ui::{prelude::*, v_stack, ContextMenu, IconElement, Label, ListItem};
use unicase::UniCase;
use util::{maybe, ResultExt, TryFutureExt};
use workspace::{
@@ -2845,7 +2844,7 @@ mod tests {
let worktree = worktree.read(cx);
if let Ok(relative_path) = path.strip_prefix(worktree.root_name()) {
let entry_id = worktree.entry_for_path(relative_path).unwrap().id;
- panel.selection = Some(Selection {
+ panel.selection = Some(crate::Selection {
worktree_id: worktree.id(),
entry_id,
});
diff --git a/crates/theme_selector2/src/theme_selector.rs b/crates/theme_selector2/src/theme_selector.rs
index 7b0a0c3d3ae..be55194e76e 100644
--- a/crates/theme_selector2/src/theme_selector.rs
+++ b/crates/theme_selector2/src/theme_selector.rs
@@ -2,14 +2,14 @@ use feature_flags::FeatureFlagAppExt;
use fs::Fs;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{
- actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render,
- SharedString, View, ViewContext, VisualContext, WeakView,
+ actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, SharedString, View,
+ ViewContext, VisualContext, WeakView,
};
use picker::{Picker, PickerDelegate};
use settings::{update_settings_file, SettingsStore};
use std::sync::Arc;
-use theme::{ActiveTheme, Theme, ThemeRegistry, ThemeSettings};
-use ui::ListItem;
+use theme::{Theme, ThemeRegistry, ThemeSettings};
+use ui::{prelude::*, ListItem};
use util::ResultExt;
use workspace::{ui::HighlightedLabel, Workspace};
diff --git a/crates/ui2/src/components/list/list_header.rs b/crates/ui2/src/components/list/list_header.rs
index 8761acd6086..431665ffd34 100644
--- a/crates/ui2/src/components/list/list_header.rs
+++ b/crates/ui2/src/components/list/list_header.rs
@@ -62,8 +62,10 @@ impl ListHeader {
self.meta = meta;
self
}
+}
- pub fn selected(mut self, selected: bool) -> Self {
+impl Selectable for ListHeader {
+ fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
diff --git a/crates/ui2/src/components/list/list_item.rs b/crates/ui2/src/components/list/list_item.rs
index 7ad1d5fb72d..85198416cd9 100644
--- a/crates/ui2/src/components/list/list_item.rs
+++ b/crates/ui2/src/components/list/list_item.rs
@@ -83,11 +83,6 @@ impl ListItem {
self
}
- pub fn selected(mut self, selected: bool) -> Self {
- self.selected = selected;
- self
- }
-
pub fn left_child(mut self, left_content: impl IntoElement) -> Self {
self.left_slot = Some(left_content.into_any_element());
self
@@ -109,6 +104,13 @@ impl ListItem {
}
}
+impl Selectable for ListItem {
+ fn selected(mut self, selected: bool) -> Self {
+ self.selected = selected;
+ self
+ }
+}
+
impl ParentElement for ListItem {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
&mut self.children
diff --git a/crates/ui2/src/ui2.rs b/crates/ui2/src/ui2.rs
index 7b054890a68..6c5669741be 100644
--- a/crates/ui2/src/ui2.rs
+++ b/crates/ui2/src/ui2.rs
@@ -18,7 +18,6 @@ mod disableable;
mod fixed;
pub mod prelude;
mod selectable;
-mod slot;
mod styled_ext;
mod styles;
pub mod utils;
@@ -29,6 +28,5 @@ pub use disableable::*;
pub use fixed::*;
pub use prelude::*;
pub use selectable::*;
-pub use slot::*;
pub use styled_ext::*;
pub use styles::*;
diff --git a/crates/welcome2/src/base_keymap_picker.rs b/crates/welcome2/src/base_keymap_picker.rs
index f28aa7dc308..4e829972f0c 100644
--- a/crates/welcome2/src/base_keymap_picker.rs
+++ b/crates/welcome2/src/base_keymap_picker.rs
@@ -1,14 +1,14 @@
use super::base_keymap_setting::BaseKeymap;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{
- actions, AppContext, DismissEvent, EventEmitter, FocusableView, ParentElement, Render, Task,
- View, ViewContext, VisualContext, WeakView,
+ actions, AppContext, DismissEvent, EventEmitter, FocusableView, Render, Task, View,
+ ViewContext, VisualContext, WeakView,
};
use picker::{Picker, PickerDelegate};
use project::Fs;
use settings::{update_settings_file, Settings};
use std::sync::Arc;
-use ui::ListItem;
+use ui::{prelude::*, ListItem};
use util::ResultExt;
use workspace::{ui::HighlightedLabel, Workspace};