Skip to content

Visual Studio Code, rebuilt in Rust

Rust

perf(port): draw the secondary side bar as a cached part view

rokartur27d00466d5a9
diff --git a/native/crates/app/src/workbench/part_grid.rs b/native/crates/app/src/workbench/part_grid.rs
index 22405fc7e2f..77e6678a1d0 100644
--- a/native/crates/app/src/workbench/part_grid.rs
+++ b/native/crates/app/src/workbench/part_grid.rs
@@ -524,13 +524,7 @@ impl Workbench {
let mut section = div().relative().h(px(height)).flex_none();
for &(part, rect) in &parts {
let [left, top, right, bottom] = if compact { [0.; 4] } else { card_margins(part, rect, &parts, arrangement, width, height, false) };
- let content = match part {
- Part::ActivityBar => self.part_view(CachedPart::Grid(Part::ActivityBar), cx),
- Part::SideBar => self.part_view(CachedPart::Grid(Part::SideBar), cx),
- Part::Editor => self.part_view(CachedPart::Grid(Part::Editor), cx),
- Part::Panel => self.part_view(CachedPart::Grid(Part::Panel), cx),
- Part::AuxiliaryBar => self.auxiliary_bar_part(window, cx).into_any_element(),
- };
+ let content = self.part_view(CachedPart::Grid(part), cx);
let [x, y, w, h] = rect;
section = section.child(div().absolute().left(px(x)).top(px(y)).w(px(w)).h(px(h)).flex().pl(px(left)).pt(px(top)).pr(px(right)).pb(px(bottom)).child(content));
}
diff --git a/native/crates/app/src/workbench/part_view.rs b/native/crates/app/src/workbench/part_view.rs
index 7f22e3ae825..a8131a45d1b 100644
--- a/native/crates/app/src/workbench/part_view.rs
+++ b/native/crates/app/src/workbench/part_view.rs
@@ -91,6 +91,7 @@ impl Workbench {
CachedPart::Grid(Part::Editor) => self.in_part(super::editor_groups::MAIN_PART, |workbench| workbench.editor_groups_part(window, cx)),
CachedPart::Grid(Part::Panel) => self.panel_part(window, cx),
CachedPart::Grid(Part::ActivityBar) => self.activity_bar(window, cx),
+ CachedPart::Grid(Part::AuxiliaryBar) => self.auxiliary_bar_part(window, cx),
// The title and the status bar's editor items follow the main part's active editor (windowTitle.ts and
// editorStatus.ts are scoped to the window's part).
CachedPart::TitleBar => {
@@ -103,7 +104,6 @@ impl Workbench {
let main_group = self.part_active_group(super::editor_groups::MAIN_PART).expect("the main part has a group");
self.with_group(main_group, |workbench| workbench.status_bar(window, cx)).w_full()
}
- _ => unreachable!("{part:?} is drawn by the workbench"),
};
// The labels drawn above asked for the decorations they lack.
self.send_decoration_requests(window.current_view(), cx);
diff --git a/native/crates/app/src/workbench/part_view/tests.rs b/native/crates/app/src/workbench/part_view/tests.rs
index aac6a5d94ec..719f160cdb0 100644
--- a/native/crates/app/src/workbench/part_view/tests.rs
+++ b/native/crates/app/src/workbench/part_view/tests.rs
@@ -87,12 +87,15 @@ fn the_side_bar_draws_again_on_a_workbench_change_and_its_own_scroll_only(cx: &m
std::fs::remove_dir_all(dir).unwrap();
}
-/// The panel, the status bar, the activity bar and the title bar are cached: a scroll of the Explorer leaves them as
-/// drawn, a workbench change draws them again.
+/// The panel, the secondary side bar, the status bar, the activity bar and the title bar are cached: a scroll of the
+/// Explorer leaves them as drawn, a workbench change draws them again.
#[gpui::test]
fn the_other_parts_stay_cached_through_a_side_bar_scroll(cx: &mut TestAppContext) {
let (dir, workbench, cx) = explorer("panel", cx);
- workbench.update(cx, |workbench, cx| workbench.set_part_hidden(Part::Panel, false, cx));
+ workbench.update(cx, |workbench, cx| {
+ workbench.set_part_hidden(Part::Panel, false, cx);
+ workbench.set_part_hidden(Part::AuxiliaryBar, false, cx);
+ });
cx.run_until_parked();
let bounds = workbench.read_with(cx, |workbench, _| workbench.list_scroller(ListId::Explorer).bounds());
cx.simulate_mouse_move(bounds.center(), None, Modifiers::none());
@@ -101,7 +104,7 @@ fn the_other_parts_stay_cached_through_a_side_bar_scroll(cx: &mut TestAppContext
cx.run_until_parked();
let (renders, status_bar, activity_bar) = (part_renders(&workbench, Part::Panel, cx), view_renders(&workbench, CachedPart::StatusBar, cx), part_renders(&workbench, Part::ActivityBar, cx));
- let title_bar = view_renders(&workbench, CachedPart::TitleBar, cx);
+ let (title_bar, auxiliary_bar) = (view_renders(&workbench, CachedPart::TitleBar, cx), part_renders(&workbench, Part::AuxiliaryBar, cx));
cx.simulate_event(ScrollWheelEvent { position: bounds.center(), delta: ScrollDelta::Lines(point(0., -1.)), modifiers: Modifiers::none(), ..Default::default() });
cx.run_until_parked();
draw(cx);
@@ -110,6 +113,7 @@ fn the_other_parts_stay_cached_through_a_side_bar_scroll(cx: &mut TestAppContext
assert_eq!(view_renders(&workbench, CachedPart::StatusBar, cx), status_bar, "the Explorer's scroll reuses the status bar");
assert_eq!(part_renders(&workbench, Part::ActivityBar, cx), activity_bar, "the Explorer's scroll reuses the activity bar");
assert_eq!(view_renders(&workbench, CachedPart::TitleBar, cx), title_bar, "the Explorer's scroll reuses the title bar");
+ assert_eq!(part_renders(&workbench, Part::AuxiliaryBar, cx), auxiliary_bar, "the Explorer's scroll reuses the secondary side bar");
workbench.update(cx, |_, cx| cx.notify());
cx.run_until_parked();
@@ -118,6 +122,7 @@ fn the_other_parts_stay_cached_through_a_side_bar_scroll(cx: &mut TestAppContext
assert!(view_renders(&workbench, CachedPart::StatusBar, cx) > status_bar, "a workbench change draws the status bar");
assert!(part_renders(&workbench, Part::ActivityBar, cx) > activity_bar, "a workbench change draws the activity bar");
assert!(view_renders(&workbench, CachedPart::TitleBar, cx) > title_bar, "a workbench change draws the title bar");
+ assert!(part_renders(&workbench, Part::AuxiliaryBar, cx) > auxiliary_bar, "a workbench change draws the secondary side bar");
std::fs::remove_dir_all(dir).unwrap();
}