Improve cursor style behavior for some draggable elements (#31965)
Follow-up to #24797 This PR ensures some cursor styles do not change for draggable elements during dragging. The linked PR covered this on the higher level for draggable divs. However, e.g. the pane divider inbetween two editors is not a draggable div and thus still has the issue that the cursor style changes during dragging. This PR fixes this issue by setting the hitbox to `None` in cases where the element is currently being dragged, which ensures the cursor style is applied to the cursor no matter what during dragging. Namely, this change fixes this for - non-div pane dividers - minimap slider and the - editor scrollbars and implements it for the UI scrollbars (Notably, UI scrollbars do already have `cursor_default` on their parent container but would not keep this during dragging. I opted out on removing this from the parent containers until #30194 or a similar PR is merged). https://github.com/user-attachments/assets/f97859dd-5f1d-4449-ab92-c27f2d933c4a Release Notes: - N/A
This commit is contained in:
parent
e0057ccd0f
commit
2fe1293fba
11 changed files with 88 additions and 43 deletions
|
@ -5131,7 +5131,7 @@ impl EditorElement {
|
|||
let is_singleton = self.editor.read(cx).is_singleton(cx);
|
||||
|
||||
let line_height = layout.position_map.line_height;
|
||||
window.set_cursor_style(CursorStyle::Arrow, Some(&layout.gutter_hitbox));
|
||||
window.set_cursor_style(CursorStyle::Arrow, &layout.gutter_hitbox);
|
||||
|
||||
for LineNumberLayout {
|
||||
shaped_line,
|
||||
|
@ -5158,9 +5158,9 @@ impl EditorElement {
|
|||
// In singleton buffers, we select corresponding lines on the line number click, so use | -like cursor.
|
||||
// In multi buffers, we open file at the line number clicked, so use a pointing hand cursor.
|
||||
if is_singleton {
|
||||
window.set_cursor_style(CursorStyle::IBeam, Some(&hitbox));
|
||||
window.set_cursor_style(CursorStyle::IBeam, &hitbox);
|
||||
} else {
|
||||
window.set_cursor_style(CursorStyle::PointingHand, Some(&hitbox));
|
||||
window.set_cursor_style(CursorStyle::PointingHand, &hitbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5378,7 +5378,7 @@ impl EditorElement {
|
|||
.read(cx)
|
||||
.all_diff_hunks_expanded()
|
||||
{
|
||||
window.set_cursor_style(CursorStyle::PointingHand, Some(hunk_hitbox));
|
||||
window.set_cursor_style(CursorStyle::PointingHand, hunk_hitbox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5452,7 +5452,7 @@ impl EditorElement {
|
|||
|window| {
|
||||
let editor = self.editor.read(cx);
|
||||
if editor.mouse_cursor_hidden {
|
||||
window.set_cursor_style(CursorStyle::None, None);
|
||||
window.set_window_cursor_style(CursorStyle::None);
|
||||
} else if editor
|
||||
.hovered_link_state
|
||||
.as_ref()
|
||||
|
@ -5460,13 +5460,10 @@ impl EditorElement {
|
|||
{
|
||||
window.set_cursor_style(
|
||||
CursorStyle::PointingHand,
|
||||
Some(&layout.position_map.text_hitbox),
|
||||
&layout.position_map.text_hitbox,
|
||||
);
|
||||
} else {
|
||||
window.set_cursor_style(
|
||||
CursorStyle::IBeam,
|
||||
Some(&layout.position_map.text_hitbox),
|
||||
);
|
||||
window.set_cursor_style(CursorStyle::IBeam, &layout.position_map.text_hitbox);
|
||||
};
|
||||
|
||||
self.paint_lines_background(layout, window, cx);
|
||||
|
@ -5607,6 +5604,7 @@ impl EditorElement {
|
|||
let Some(scrollbars_layout) = layout.scrollbars_layout.take() else {
|
||||
return;
|
||||
};
|
||||
let any_scrollbar_dragged = self.editor.read(cx).scroll_manager.any_scrollbar_dragged();
|
||||
|
||||
for (scrollbar_layout, axis) in scrollbars_layout.iter_scrollbars() {
|
||||
let hitbox = &scrollbar_layout.hitbox;
|
||||
|
@ -5672,7 +5670,11 @@ impl EditorElement {
|
|||
BorderStyle::Solid,
|
||||
));
|
||||
|
||||
window.set_cursor_style(CursorStyle::Arrow, Some(&hitbox));
|
||||
if any_scrollbar_dragged {
|
||||
window.set_window_cursor_style(CursorStyle::Arrow);
|
||||
} else {
|
||||
window.set_cursor_style(CursorStyle::Arrow, &hitbox);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -5740,7 +5742,7 @@ impl EditorElement {
|
|||
}
|
||||
});
|
||||
|
||||
if self.editor.read(cx).scroll_manager.any_scrollbar_dragged() {
|
||||
if any_scrollbar_dragged {
|
||||
window.on_mouse_event({
|
||||
let editor = self.editor.clone();
|
||||
move |_: &MouseUpEvent, phase, window, cx| {
|
||||
|
@ -6126,6 +6128,7 @@ impl EditorElement {
|
|||
fn paint_minimap(&self, layout: &mut EditorLayout, window: &mut Window, cx: &mut App) {
|
||||
if let Some(mut layout) = layout.minimap.take() {
|
||||
let minimap_hitbox = layout.thumb_layout.hitbox.clone();
|
||||
let dragging_minimap = self.editor.read(cx).scroll_manager.is_dragging_minimap();
|
||||
|
||||
window.paint_layer(layout.thumb_layout.hitbox.bounds, |window| {
|
||||
window.with_element_namespace("minimap", |window| {
|
||||
|
@ -6177,7 +6180,11 @@ impl EditorElement {
|
|||
});
|
||||
});
|
||||
|
||||
window.set_cursor_style(CursorStyle::Arrow, Some(&minimap_hitbox));
|
||||
if dragging_minimap {
|
||||
window.set_window_cursor_style(CursorStyle::Arrow);
|
||||
} else {
|
||||
window.set_cursor_style(CursorStyle::Arrow, &minimap_hitbox);
|
||||
}
|
||||
|
||||
let minimap_axis = ScrollbarAxis::Vertical;
|
||||
let pixels_per_line = (minimap_hitbox.size.height / layout.max_scroll_top)
|
||||
|
@ -6238,7 +6245,7 @@ impl EditorElement {
|
|||
}
|
||||
});
|
||||
|
||||
if self.editor.read(cx).scroll_manager.is_dragging_minimap() {
|
||||
if dragging_minimap {
|
||||
window.on_mouse_event({
|
||||
let editor = self.editor.clone();
|
||||
move |event: &MouseUpEvent, phase, window, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue