feat: use uniform list for tree component
This commit is contained in:
@@ -33,6 +33,7 @@
|
|||||||
- Fix text typed into a field under a panel appearing up to a quarter second late
|
- Fix text typed into a field under a panel appearing up to a quarter second late
|
||||||
- Fix an open dialog taking keyboard focus back from the command palette or a toast button on every repaint
|
- Fix an open dialog taking keyboard focus back from the command palette or a toast button on every repaint
|
||||||
- Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal
|
- Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal
|
||||||
|
- Fix the file tree's scrollbar sitting inset from the sidebar's right border, it now rides beside it
|
||||||
|
|
||||||
## v0.2.0 - 2026/10/21
|
## v0.2.0 - 2026/10/21
|
||||||
|
|
||||||
|
|||||||
@@ -260,12 +260,9 @@ impl RepoFilesView {
|
|||||||
let change_view = view.clone();
|
let change_view = view.clone();
|
||||||
let disclosure_view = view;
|
let disclosure_view = view;
|
||||||
|
|
||||||
div()
|
// Mirrors the sidebar's left inset, so rows stay aligned while the scrollbar hugs its border.
|
||||||
.flex_1()
|
|
||||||
.min_h_0()
|
|
||||||
.w_full()
|
|
||||||
.child(
|
|
||||||
Tree::new("repo-tree")
|
Tree::new("repo-tree")
|
||||||
|
.pr_2()
|
||||||
.selected(selected)
|
.selected(selected)
|
||||||
.items(move |_, _| Arc::clone(&rows))
|
.items(move |_, _| Arc::clone(&rows))
|
||||||
.on_change({
|
.on_change({
|
||||||
@@ -294,8 +291,7 @@ impl RepoFilesView {
|
|||||||
log::warn!("failed to toggle folder: {error}");
|
log::warn!("failed to toggle folder: {error}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
)
|
|
||||||
.into_any_element()
|
.into_any_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ use anyhow::Error;
|
|||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, PathPromptOptions, Render, SharedString, StatefulInteractiveElement as _,
|
ParentElement as _, PathPromptOptions, Render, SharedString, StyleRefinement, Styled as _,
|
||||||
StyleRefinement, Styled as _, Subscription, SystemNotification, Task, WeakEntity, Window, div,
|
Subscription, SystemNotification, Task, WeakEntity, Window, div, px,
|
||||||
px,
|
|
||||||
};
|
};
|
||||||
use metadata::ProfileDirectory;
|
use metadata::ProfileDirectory;
|
||||||
use nostr::prelude::{PublicKey, Url};
|
use nostr::prelude::{PublicKey, Url};
|
||||||
@@ -1441,27 +1440,28 @@ impl RepoDetailView {
|
|||||||
let commit_id = commit.id.clone();
|
let commit_id = commit.id.clone();
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
h_flex()
|
Button::new("last-commit")
|
||||||
.id("last-commit")
|
.variant(ButtonVariant::Ghost)
|
||||||
.h_8()
|
.fully_rounded(true)
|
||||||
.px_2()
|
|
||||||
.gap_2()
|
|
||||||
.min_w_0()
|
|
||||||
.rounded(cx.theme().radius.control)
|
|
||||||
.hover(|this| this.bg(cx.theme().colors.muted_hover))
|
|
||||||
.tooltip(Tooltip::text("View latest commit"))
|
.tooltip(Tooltip::text("View latest commit"))
|
||||||
.on_click(move |_, window, cx| {
|
.on_click(move |_, window, cx| {
|
||||||
history.update(cx, |history, cx| {
|
history.update(cx, |history, cx| {
|
||||||
history.open_commit_diff(&commit_id, window, cx);
|
history.open_commit_diff(&commit_id, window, cx);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.child(Icon::named(IconRole::GitCommit).color(cx.theme().colors.muted_foreground))
|
.child(
|
||||||
|
h_flex()
|
||||||
|
.w_full()
|
||||||
|
.gap_2()
|
||||||
|
.child(
|
||||||
|
Icon::named(IconRole::GitCommit)
|
||||||
|
.color(cx.theme().colors.muted_foreground),
|
||||||
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.font_family(cx.theme().mono_font)
|
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.text_color(cx.theme().colors.muted_foreground)
|
.text_color(cx.theme().colors.muted_foreground)
|
||||||
.child(SharedString::from(short)),
|
.child(SharedString::from(&short)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
@@ -1469,14 +1469,16 @@ impl RepoDetailView {
|
|||||||
.text_sm()
|
.text_sm()
|
||||||
.text_ellipsis()
|
.text_ellipsis()
|
||||||
.whitespace_nowrap()
|
.whitespace_nowrap()
|
||||||
.child(commit.summary.clone()),
|
.child(SharedString::from(&commit.summary)),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.text_color(cx.theme().colors.muted_foreground)
|
.text_color(cx.theme().colors.muted_foreground)
|
||||||
.child(relative_time_secs(commit.time)),
|
.child(SharedString::from(relative_time_secs(commit.time))),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
.flex_1()
|
||||||
.into_any_element(),
|
.into_any_element(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ use crate::components::common::{
|
|||||||
StyledExt as _, nav_key, paint_selectable_row, selectable_label_color,
|
StyledExt as _, nav_key, paint_selectable_row, selectable_label_color,
|
||||||
};
|
};
|
||||||
use crate::components::grain::grain as grain_overlay;
|
use crate::components::grain::grain as grain_overlay;
|
||||||
use crate::components::scroll_area::ScrollArea;
|
|
||||||
use crate::theme::{ActiveTheme as _, BORDER_WIDTH, SIDEBAR_DEFAULT_WIDTH};
|
use crate::theme::{ActiveTheme as _, BORDER_WIDTH, SIDEBAR_DEFAULT_WIDTH};
|
||||||
|
|
||||||
/// The change reporter, fired with the next selected row by pointer and keys.
|
/// The change reporter, fired with the next selected row by pointer and keys.
|
||||||
@@ -397,24 +396,19 @@ impl RenderOnce for Sidebar {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let focus = crate::components::common::focus_handle(&id, window, cx);
|
let focus = crate::components::common::focus_handle(&id, window, cx);
|
||||||
let scroll = window.with_element_namespace(id.clone(), |window| {
|
|
||||||
window
|
|
||||||
.use_keyed_state("scroll", cx, |_, _| gpui::ScrollHandle::new())
|
|
||||||
.clone()
|
|
||||||
});
|
|
||||||
let scroll_area_id = (id.clone(), "entries");
|
|
||||||
|
|
||||||
let row_count = entries
|
let row_count = entries
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|entry| matches!(entry, SidebarEntry::Row { .. }))
|
.filter(|entry| matches!(entry, SidebarEntry::Row { .. }))
|
||||||
.count();
|
.count();
|
||||||
let mut row_position = 0usize;
|
|
||||||
|
|
||||||
let children: Vec<AnyElement> = entries
|
let mut row_position = 0usize;
|
||||||
.into_iter()
|
let mut list_children = Vec::new();
|
||||||
.enumerate()
|
let mut custom_children = Vec::new();
|
||||||
.map(|(index, entry)| {
|
|
||||||
|
for (index, entry) in entries.into_iter().enumerate() {
|
||||||
let is_row = matches!(entry, SidebarEntry::Row { .. });
|
let is_row = matches!(entry, SidebarEntry::Row { .. });
|
||||||
|
let is_custom = matches!(entry, SidebarEntry::Custom(_));
|
||||||
|
|
||||||
if is_row {
|
if is_row {
|
||||||
row_position += 1;
|
row_position += 1;
|
||||||
@@ -426,7 +420,7 @@ impl RenderOnce for Sidebar {
|
|||||||
(0, 0)
|
(0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
entry.render_entry(
|
let rendered = entry.render_entry(
|
||||||
cx,
|
cx,
|
||||||
index,
|
index,
|
||||||
position_in_set,
|
position_in_set,
|
||||||
@@ -435,9 +429,14 @@ impl RenderOnce for Sidebar {
|
|||||||
material,
|
material,
|
||||||
&on_change,
|
&on_change,
|
||||||
&focus,
|
&focus,
|
||||||
)
|
);
|
||||||
})
|
|
||||||
.collect();
|
if is_custom {
|
||||||
|
custom_children.push(rendered);
|
||||||
|
} else {
|
||||||
|
list_children.push(rendered);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let theme = cx.theme();
|
let theme = cx.theme();
|
||||||
|
|
||||||
@@ -456,8 +455,7 @@ impl RenderOnce for Sidebar {
|
|||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.id((id.clone(), "list"))
|
.id((id.clone(), "list"))
|
||||||
.flex_1()
|
.flex_none()
|
||||||
.min_h_0()
|
|
||||||
.track_focus(&focus)
|
.track_focus(&focus)
|
||||||
.focusable()
|
.focusable()
|
||||||
.tab_stop(true)
|
.tab_stop(true)
|
||||||
@@ -475,19 +473,22 @@ impl RenderOnce for Sidebar {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.child(
|
|
||||||
ScrollArea::new(scroll_area_id)
|
|
||||||
.handle(scroll.read(cx).clone())
|
|
||||||
.h_full()
|
|
||||||
.child(
|
.child(
|
||||||
v_flex()
|
v_flex()
|
||||||
.gap_0p5()
|
.gap_0p5()
|
||||||
.when(padded, |content| content.p_2())
|
.when(padded, |content| content.p_2())
|
||||||
.children(children),
|
.children(list_children),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into_any_element(),
|
.when(!custom_children.is_empty(), |sidebar| {
|
||||||
|
sidebar.child(
|
||||||
|
v_flex()
|
||||||
|
.flex_1()
|
||||||
|
.min_h_0()
|
||||||
|
.when(padded, |content| content.pl_2())
|
||||||
|
.children(custom_children),
|
||||||
)
|
)
|
||||||
|
})
|
||||||
.when(material && grain, |sidebar| sidebar.child(grain_overlay()))
|
.when(material && grain, |sidebar| sidebar.child(grain_overlay()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,14 @@ use gpui::prelude::FluentBuilder;
|
|||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
|
AnyElement, App, ElementId, FocusHandle, InteractiveElement as _, IntoElement, KeyDownEvent,
|
||||||
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
ParentElement as _, RenderOnce, Role, SharedString, StatefulInteractiveElement as _,
|
||||||
StyleRefinement, Styled as _, Window, div, rems,
|
StyleRefinement, Styled as _, UniformListScrollHandle, Window, div, rems, uniform_list,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::common::{focus_handle, h_flex};
|
||||||
use crate::components::common::{
|
use crate::components::common::{
|
||||||
StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, v_flex,
|
StyledExt as _, nav_key, paint_selectable_row, selectable_label_color, v_flex,
|
||||||
};
|
};
|
||||||
|
use crate::components::scrollbar::Scrollbar;
|
||||||
use crate::icons::{Icon, IconRole, icon};
|
use crate::icons::{Icon, IconRole, icon};
|
||||||
use crate::theme::ActiveTheme as _;
|
use crate::theme::ActiveTheme as _;
|
||||||
|
|
||||||
@@ -138,15 +140,14 @@ impl TreeItem {
|
|||||||
let depth = self.depth.min(TREE_MAX_DEPTH) as f32;
|
let depth = self.depth.min(TREE_MAX_DEPTH) as f32;
|
||||||
let indent = rems(0.75 * if self.depth == 0 { 0.5 } else { depth + 1.0 });
|
let indent = rems(0.75 * if self.depth == 0 { 0.5 } else { depth + 1.0 });
|
||||||
|
|
||||||
div()
|
h_flex()
|
||||||
.id((self.key.clone(), "tree-item"))
|
.id((self.key.clone(), "tree-item"))
|
||||||
.relative()
|
.relative()
|
||||||
.flex()
|
|
||||||
.items_center()
|
|
||||||
.gap_2()
|
.gap_2()
|
||||||
.pl(indent)
|
.pl(indent)
|
||||||
.pr_2()
|
.pr_2()
|
||||||
.py_1()
|
.py_1()
|
||||||
|
.w_full()
|
||||||
.min_h_8()
|
.min_h_8()
|
||||||
.rounded(theme.radius.sm)
|
.rounded(theme.radius.sm)
|
||||||
.role(Role::TreeItem)
|
.role(Role::TreeItem)
|
||||||
@@ -551,10 +552,21 @@ impl gpui::Styled for Tree {
|
|||||||
|
|
||||||
impl RenderOnce for Tree {
|
impl RenderOnce for Tree {
|
||||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||||
let items = match self.items {
|
let Tree {
|
||||||
|
id,
|
||||||
|
selected,
|
||||||
|
a11y_label,
|
||||||
|
on_change,
|
||||||
|
on_disclosure,
|
||||||
|
items,
|
||||||
|
style,
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
let items = match items {
|
||||||
Some(build) => build(window, cx),
|
Some(build) => build(window, cx),
|
||||||
None => Arc::default(),
|
None => Arc::default(),
|
||||||
};
|
};
|
||||||
|
let count = items.len();
|
||||||
|
|
||||||
let selectable: Vec<usize> = items
|
let selectable: Vec<usize> = items
|
||||||
.iter()
|
.iter()
|
||||||
@@ -563,49 +575,41 @@ impl RenderOnce for Tree {
|
|||||||
.map(|(index, _)| index)
|
.map(|(index, _)| index)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let focus = crate::components::common::focus_handle(&self.id, window, cx);
|
let focus = focus_handle(&id, window, cx);
|
||||||
|
let label = a11y_label.unwrap_or_else(|| SharedString::from(id.to_string()));
|
||||||
let label = self
|
|
||||||
.a11y_label
|
|
||||||
.clone()
|
|
||||||
.unwrap_or_else(|| SharedString::from(self.id.to_string()));
|
|
||||||
|
|
||||||
let sibling_sets = Self::sibling_sets(&items);
|
let sibling_sets = Self::sibling_sets(&items);
|
||||||
|
|
||||||
let rows: Vec<AnyElement> = items
|
let scroll = window.with_element_namespace(id.clone(), |window| {
|
||||||
.iter()
|
window.use_keyed_state("scroll", cx, |_, _| UniformListScrollHandle::new())
|
||||||
.enumerate()
|
});
|
||||||
.map(|(index, item)| {
|
let scroll_handle = scroll.read(cx).clone();
|
||||||
let (position_in_set, size_of_set) = sibling_sets[index];
|
|
||||||
item.render_row(
|
let rows_id = (id.clone(), "rows");
|
||||||
cx,
|
let scroll_id = (id.clone(), "scroll");
|
||||||
index,
|
let items_for_rows = Arc::clone(&items);
|
||||||
position_in_set,
|
let on_change_for_rows = on_change.clone();
|
||||||
size_of_set,
|
let on_disclosure_for_rows = on_disclosure.clone();
|
||||||
self.selected == Some(index),
|
let focus_for_rows = focus.clone();
|
||||||
&self.on_change,
|
|
||||||
&self.on_disclosure,
|
// Padding insets the rows, leaving the scrollbar on the tree's edge.
|
||||||
&focus,
|
let mut style = style;
|
||||||
)
|
let row_style = StyleRefinement {
|
||||||
})
|
padding: std::mem::take(&mut style.padding),
|
||||||
.collect();
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
v_flex()
|
v_flex()
|
||||||
.id(self.id)
|
.relative()
|
||||||
.gap_0p5()
|
.id(id)
|
||||||
.text_sm()
|
.text_sm()
|
||||||
.refine_style(&self.style)
|
.refine_style(&style)
|
||||||
|
.size_full()
|
||||||
.track_focus(&focus)
|
.track_focus(&focus)
|
||||||
.focusable()
|
.focusable()
|
||||||
.tab_stop(true)
|
.tab_stop(true)
|
||||||
.role(Role::Tree)
|
.role(Role::Tree)
|
||||||
.aria_label(label)
|
.aria_label(label)
|
||||||
.on_key_down({
|
.on_key_down(move |event: &KeyDownEvent, window, cx| {
|
||||||
let selected = self.selected;
|
|
||||||
let on_change = self.on_change.clone();
|
|
||||||
let on_disclosure = self.on_disclosure.clone();
|
|
||||||
|
|
||||||
move |event: &KeyDownEvent, window, cx| {
|
|
||||||
if nav_key(&selectable, selected, &event.keystroke.key, |next| {
|
if nav_key(&selectable, selected, &event.keystroke.key, |next| {
|
||||||
if let Some(on_change) = &on_change {
|
if let Some(on_change) = &on_change {
|
||||||
on_change(next, window, cx);
|
on_change(next, window, cx);
|
||||||
@@ -647,8 +651,33 @@ impl RenderOnce for Tree {
|
|||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
cx.stop_propagation();
|
cx.stop_propagation();
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.children(rows)
|
.child(
|
||||||
|
uniform_list(rows_id, count, move |range, _, cx| {
|
||||||
|
range
|
||||||
|
.map(|index| {
|
||||||
|
let Some(item) = items_for_rows.get(index) else {
|
||||||
|
return div().into_any_element();
|
||||||
|
};
|
||||||
|
let (position_in_set, size_of_set) = sibling_sets[index];
|
||||||
|
|
||||||
|
item.render_row(
|
||||||
|
cx,
|
||||||
|
index,
|
||||||
|
position_in_set,
|
||||||
|
size_of_set,
|
||||||
|
selected == Some(index),
|
||||||
|
&on_change_for_rows,
|
||||||
|
&on_disclosure_for_rows,
|
||||||
|
&focus_for_rows,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
})
|
||||||
|
.track_scroll(&scroll_handle)
|
||||||
|
.refine_style(&row_style)
|
||||||
|
.size_full(),
|
||||||
|
)
|
||||||
|
.child(Scrollbar::vertical(scroll_id, scroll_handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user