From 0b34b1de7b74cf14d5aa03e8bb71272adad98e40 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 5 Mar 2024 21:54:48 +0800 Subject: [PATCH] Fix first/last item margin on scroll (#8880) ![output](https://github.com/zed-industries/zed/assets/5518/e39a3600-99c4-4d3c-baee-efd53a474f38) Before: https://github.com/zed-industries/zed/assets/5518/f7a4563a-504a-4a41-bfd4-21e9439cd02b After: https://github.com/zed-industries/zed/assets/5518/0ba41527-46fd-404f-8207-1b8c5cf37434 Release Notes: - Fixed first and last item margin when scroll view has padding --- crates/command_palette/src/command_palette.rs | 1 + crates/file_finder/src/file_finder.rs | 1 + crates/gpui/src/elements/list.rs | 2 +- crates/gpui/src/elements/uniform_list.rs | 8 ++++---- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/command_palette/src/command_palette.rs b/crates/command_palette/src/command_palette.rs index 0cd7f581de..c8a98962c9 100644 --- a/crates/command_palette/src/command_palette.rs +++ b/crates/command_palette/src/command_palette.rs @@ -396,6 +396,7 @@ impl PickerDelegate for CommandPaletteDelegate { .child( h_flex() .w_full() + .py_px() .justify_between() .child(HighlightedLabel::new( command.name.clone(), diff --git a/crates/file_finder/src/file_finder.rs b/crates/file_finder/src/file_finder.rs index a8349a6335..5f2c874457 100644 --- a/crates/file_finder/src/file_finder.rs +++ b/crates/file_finder/src/file_finder.rs @@ -880,6 +880,7 @@ impl PickerDelegate for FileFinderDelegate { .child( h_flex() .gap_2() + .py_px() .child(HighlightedLabel::new(file_name, file_name_positions)) .child( HighlightedLabel::new(full_path, full_path_positions) diff --git a/crates/gpui/src/elements/list.rs b/crates/gpui/src/elements/list.rs index f449862668..90dd8da0c2 100644 --- a/crates/gpui/src/elements/list.rs +++ b/crates/gpui/src/elements/list.rs @@ -241,7 +241,7 @@ impl ListState { let mut cursor = state.items.cursor::(); cursor.seek(&Count(ix + 1), Bias::Right, &()); let bottom = cursor.start().height + padding.top; - let goal_top = px(0.).max(bottom - height); + let goal_top = px(0.).max(bottom - height + padding.bottom); cursor.seek(&Height(goal_top), Bias::Left, &()); let start_ix = cursor.start().count; diff --git a/crates/gpui/src/elements/uniform_list.rs b/crates/gpui/src/elements/uniform_list.rs index 8a6651524b..2d708f270e 100644 --- a/crates/gpui/src/elements/uniform_list.rs +++ b/crates/gpui/src/elements/uniform_list.rs @@ -221,10 +221,10 @@ impl Element for UniformList { let item_top = item_height * ix + padding.top; let item_bottom = item_top + item_height; let scroll_top = -updated_scroll_offset.y; - if item_top < scroll_top { - updated_scroll_offset.y = -item_top; - } else if item_bottom > scroll_top + list_height { - updated_scroll_offset.y = -(item_bottom - list_height); + if item_top < scroll_top + padding.top { + updated_scroll_offset.y = -(item_top) + padding.top; + } else if item_bottom > scroll_top + list_height - padding.bottom { + updated_scroll_offset.y = -(item_bottom - list_height) - padding.bottom; } scroll_offset = *updated_scroll_offset; }