Skip to content

Visual Studio Code, rebuilt in Rust

Rust

perf(workbench): draw the panel as a cached part view

rokarturf3491072cf17
diff --git a/native/crates/app/src/workbench/panel.rs b/native/crates/app/src/workbench/panel.rs
index 6bf798408d5..c87b354d7ea 100644
--- a/native/crates/app/src/workbench/panel.rs
+++ b/native/crates/app/src/workbench/panel.rs
@@ -837,9 +837,9 @@ fn fitting_tabs(tabs: &[(&'static str, f32)], active: Option<&'static str>, limi
/// Records the painted bounds and draws again when the size changed, so a layout reading them catches up at once.
fn size_tracker(bounds: Rc<Cell<Bounds<Pixels>>>) -> impl IntoElement {
gpui::canvas(
- move |painted, window, _| {
+ move |painted, window, cx| {
if bounds.get().size != painted.size {
- window.refresh();
+ super::part_view::redraw_after_frame(window, cx);
}
bounds.set(painted);
},
diff --git a/native/crates/app/src/workbench/part_grid.rs b/native/crates/app/src/workbench/part_grid.rs
index 9bdad04f708..9820286497a 100644
--- a/native/crates/app/src/workbench/part_grid.rs
+++ b/native/crates/app/src/workbench/part_grid.rs
@@ -517,7 +517,7 @@ impl Workbench {
Part::ActivityBar => self.activity_bar(window, cx).into_any_element(),
Part::SideBar => self.part_view(Part::SideBar, cx),
Part::Editor => self.part_view(Part::Editor, cx),
- Part::Panel => self.panel_part(window, cx).into_any_element(),
+ Part::Panel => self.part_view(Part::Panel, cx),
Part::AuxiliaryBar => self.auxiliary_bar_part(window, cx).into_any_element(),
};
let [x, y, w, h] = rect;
diff --git a/native/crates/app/src/workbench/part_view.rs b/native/crates/app/src/workbench/part_view.rs
index 93d0dda9de8..9d7e8b2b427 100644
--- a/native/crates/app/src/workbench/part_view.rs
+++ b/native/crates/app/src/workbench/part_view.rs
@@ -71,6 +71,7 @@ impl Workbench {
self.side_bar(window, cx)
}
Part::Editor => self.in_part(super::editor_groups::MAIN_PART, |workbench| workbench.editor_groups_part(window, cx)),
+ Part::Panel => self.panel_part(window, cx),
_ => unreachable!("{part:?} is drawn by the workbench"),
};
// The labels drawn above asked for the decorations they lack.
diff --git a/native/crates/app/src/workbench/part_view/tests.rs b/native/crates/app/src/workbench/part_view/tests.rs
index 6dba8a6023e..1d05b1452f9 100644
--- a/native/crates/app/src/workbench/part_view/tests.rs
+++ b/native/crates/app/src/workbench/part_view/tests.rs
@@ -82,6 +82,32 @@ 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 is a cached part: a scroll of the Explorer leaves it as drawn, a workbench change draws it again.
+#[gpui::test]
+fn the_panel_stays_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));
+ 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());
+ cx.run_until_parked();
+ draw(cx);
+ cx.run_until_parked();
+
+ let renders = part_renders(&workbench, Part::Panel, 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);
+ assert_eq!(workbench.read_with(cx, |workbench, _| workbench.list_scroller(ListId::Explorer).position().y), 50.);
+ assert_eq!(part_renders(&workbench, Part::Panel, cx), renders, "the Explorer's scroll reuses the panel");
+
+ workbench.update(cx, |_, cx| cx.notify());
+ cx.run_until_parked();
+ draw(cx);
+ assert!(part_renders(&workbench, Part::Panel, cx) > renders, "a workbench change draws the panel");
+ std::fs::remove_dir_all(dir).unwrap();
+}
+
/// A scroll of the main part's editor draws the editor part again and leaves the side bar and the workbench alone.
#[gpui::test]
fn an_editor_scroll_draws_the_editor_part_alone(cx: &mut TestAppContext) {