Allow editor mouse drag selection outside interactive bounds

Co-Authored-By: Antonio Scandurra <antonio@zed.dev>
This commit is contained in:
Julia 2023-12-19 13:00:21 -05:00
parent 3e6b84a726
commit e08fc0bbc0

View file

@ -488,7 +488,7 @@ impl EditorElement {
}
}
fn mouse_moved(
fn mouse_dragged(
editor: &mut Editor,
event: &MouseMoveEvent,
position_map: &PositionMap,
@ -497,8 +497,10 @@ impl EditorElement {
stacking_order: &StackingOrder,
cx: &mut ViewContext<Editor>,
) {
let modifiers = event.modifiers;
if editor.has_pending_selection() && event.pressed_button == Some(MouseButton::Left) {
if !editor.has_pending_selection() {
return;
}
let point_for_position = position_map.point_for_position(text_bounds, event.position);
let mut scroll_delta = gpui::Point::<f32>::default();
let vertical_margin = position_map.line_height.min(text_bounds.size.height / 3.0);
@ -532,6 +534,16 @@ impl EditorElement {
);
}
fn mouse_moved(
editor: &mut Editor,
event: &MouseMoveEvent,
position_map: &PositionMap,
text_bounds: Bounds<Pixels>,
gutter_bounds: Bounds<Pixels>,
stacking_order: &StackingOrder,
cx: &mut ViewContext<Editor>,
) {
let modifiers = event.modifiers;
let text_hovered = text_bounds.contains(&event.position);
let gutter_hovered = gutter_bounds.contains(&event.position);
let was_top = cx.was_top_layer(&event.position, stacking_order);
@ -2510,10 +2522,23 @@ impl EditorElement {
let stacking_order = cx.stacking_order().clone();
move |event: &MouseMoveEvent, phase, cx| {
if phase == DispatchPhase::Bubble
&& interactive_bounds.visibly_contains(&event.position, cx)
{
// if editor.has_pending_selection() && event.pressed_button == Some(MouseButton::Left) {
if phase == DispatchPhase::Bubble {
editor.update(cx, |editor, cx| {
if event.pressed_button == Some(MouseButton::Left) {
Self::mouse_dragged(
editor,
event,
&position_map,
text_bounds,
gutter_bounds,
&stacking_order,
cx,
)
}
if interactive_bounds.visibly_contains(&event.position, cx) {
Self::mouse_moved(
editor,
event,
@ -2523,6 +2548,7 @@ impl EditorElement {
&stacking_order,
cx,
)
}
});
}
}