Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(editor): hide the scrollbars under an overlay such as the palette

rokartur328408f42d93
diff --git a/native/crates/app/src/workbench/editor_menus/tests.rs b/native/crates/app/src/workbench/editor_menus/tests.rs
index e1b6616ae92..923d378a863 100644
--- a/native/crates/app/src/workbench/editor_menus/tests.rs
+++ b/native/crates/app/src/workbench/editor_menus/tests.rs
@@ -574,5 +574,11 @@ fn the_scrollbars_stay_shown_over_the_minimap_and_the_track(cx: &mut TestAppCont
assert!(shown(cx), "no timeout hides them while the pointer is over the editor");
cx.simulate_mouse_move(point(px(bounds.left() - 20.), y), None, gpui::Modifiers::none());
assert!(!shown(cx), "leaving the editor hides them");
+ workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("workbench.action.showCommands", Vec::new(), window, cx)));
+ cx.run_until_parked();
+ let palette = workbench.read_with(cx, |workbench, _| workbench.list_scroller(crate::workbench::list_scroll::ListId::QuickInput).bounds());
+ assert!(bounds.contains(&palette.center().map(f32::from)), "the palette covers the editor: {palette:?}");
+ cx.simulate_mouse_move(palette.center(), None, gpui::Modifiers::none());
+ assert!(!shown(cx), "the palette over the editor hides them");
std::fs::remove_dir_all(dir).unwrap();
}
diff --git a/native/crates/app/src/workbench/editor_view.rs b/native/crates/app/src/workbench/editor_view.rs
index 59a142fcb0c..dc1ca49788c 100644
--- a/native/crates/app/src/workbench/editor_view.rs
+++ b/native/crates/app/src/workbench/editor_view.rs
@@ -1371,7 +1371,6 @@ impl Workbench {
workbench.coverage_mouse_moved(false, None, cx);
}
}))
- .child(self.scrollbars_mouse_over_listener((group, model_id), cx).absolute().inset_0())
// The line's row sets `row_target` first: moves bubble from the row up to the text area.
.on_mouse_move(cx.listener(|workbench, event: &MouseMoveEvent, window, cx| {
let row_target = workbench.content_hover.row_target.take();
@@ -1563,6 +1562,8 @@ impl Workbench {
.children(self.exception_widget_element(editor, metrics.content_left(), cx))
})
.children(self.editor_inset_elements(editor, metrics.content_left()))
+ // Last: its hitbox is over the editor's own children, under a workbench overlay.
+ .child(self.scrollbars_mouse_over_listener((group, model_id), cx).absolute().inset_0())
}
/// wordHighlighter.ts: `onDidBlurEditorWidget` stops the highlights once no code editor has the focus,
@@ -1774,15 +1775,15 @@ impl Workbench {
/// editorScrollbar.ts `listenOnDomNode: viewDomNode`: mouseover and mouseleave of the whole editor, minimap, sticky
/// scroll and scrollbars included; their hitboxes block the text area's `on_hover`.
- fn scrollbars_mouse_over_listener(&self, editor: (u32, u32), cx: &mut Context<Self>) -> gpui::Canvas<()> {
+ fn scrollbars_mouse_over_listener(&self, editor: (u32, u32), cx: &mut Context<Self>) -> gpui::Canvas<gpui::Hitbox> {
let workbench = cx.entity();
canvas(
- |_, _, _| {},
- move |bounds, _, window, _| {
+ |bounds, window, _| window.insert_hitbox(bounds, gpui::HitboxBehavior::Normal),
+ move |_, hitbox, window, _| {
let moved = workbench.clone();
- window.on_mouse_event(move |event: &MouseMoveEvent, phase, _, cx| {
+ window.on_mouse_event(move |_: &MouseMoveEvent, phase, window, cx| {
if phase == DispatchPhase::Bubble {
- moved.update(cx, |workbench, cx| workbench.set_scrollbars_mouse_over(editor, bounds.contains(&event.position), cx));
+ moved.update(cx, |workbench, cx| workbench.set_scrollbars_mouse_over(editor, hitbox.should_handle_scroll(window), cx));
}
});
window.on_mouse_event(move |_: &gpui::MouseExitEvent, phase, _, cx| {