This commit is contained in:
Antonio Scandurra 2023-12-08 14:24:58 +01:00
parent 28dfd3ab43
commit 9b0bea32ed

View file

@ -385,17 +385,17 @@ impl EditorElement {
gutter_bounds: Bounds<Pixels>, gutter_bounds: Bounds<Pixels>,
stacking_order: &StackingOrder, stacking_order: &StackingOrder,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) {
let mut click_count = event.click_count; let mut click_count = event.click_count;
let modifiers = event.modifiers; let modifiers = event.modifiers;
if gutter_bounds.contains_point(&event.position) { if gutter_bounds.contains_point(&event.position) {
click_count = 3; // Simulate triple-click when clicking the gutter to select lines click_count = 3; // Simulate triple-click when clicking the gutter to select lines
} else if !text_bounds.contains_point(&event.position) { } else if !text_bounds.contains_point(&event.position) {
return false; return;
} }
if !cx.was_top_layer(&event.position, stacking_order) { if !cx.was_top_layer(&event.position, stacking_order) {
return false; return;
} }
let point_for_position = position_map.point_for_position(text_bounds, event.position); let point_for_position = position_map.point_for_position(text_bounds, event.position);
@ -427,7 +427,7 @@ impl EditorElement {
); );
} }
true cx.stop_propagation();
} }
fn mouse_right_down( fn mouse_right_down(
@ -436,9 +436,9 @@ impl EditorElement {
position_map: &PositionMap, position_map: &PositionMap,
text_bounds: Bounds<Pixels>, text_bounds: Bounds<Pixels>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) {
if !text_bounds.contains_point(&event.position) { if !text_bounds.contains_point(&event.position) {
return false; return;
} }
let point_for_position = position_map.point_for_position(text_bounds, event.position); let point_for_position = position_map.point_for_position(text_bounds, event.position);
mouse_context_menu::deploy_context_menu( mouse_context_menu::deploy_context_menu(
@ -447,7 +447,7 @@ impl EditorElement {
point_for_position.previous_valid, point_for_position.previous_valid,
cx, cx,
); );
true cx.stop_propagation();
} }
fn mouse_up( fn mouse_up(
@ -457,7 +457,7 @@ impl EditorElement {
text_bounds: Bounds<Pixels>, text_bounds: Bounds<Pixels>,
stacking_order: &StackingOrder, stacking_order: &StackingOrder,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) {
let end_selection = editor.has_pending_selection(); let end_selection = editor.has_pending_selection();
let pending_nonempty_selections = editor.has_pending_nonempty_selection(); let pending_nonempty_selections = editor.has_pending_nonempty_selection();
@ -479,10 +479,10 @@ impl EditorElement {
go_to_fetched_definition(editor, point, split, cx); go_to_fetched_definition(editor, point, split, cx);
} }
return true; cx.stop_propagation();
} else if end_selection {
cx.stop_propagation();
} }
end_selection
} }
fn mouse_moved( fn mouse_moved(
@ -493,7 +493,7 @@ impl EditorElement {
gutter_bounds: Bounds<Pixels>, gutter_bounds: Bounds<Pixels>,
stacking_order: &StackingOrder, stacking_order: &StackingOrder,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) {
let modifiers = event.modifiers; let modifiers = event.modifiers;
if editor.has_pending_selection() && event.pressed_button == Some(MouseButton::Left) { if editor.has_pending_selection() && event.pressed_button == Some(MouseButton::Left) {
let point_for_position = position_map.point_for_position(text_bounds, event.position); let point_for_position = position_map.point_for_position(text_bounds, event.position);
@ -562,11 +562,13 @@ impl EditorElement {
} }
} }
true cx.stop_propagation();
} else { } else {
update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx); update_go_to_definition_link(editor, None, modifiers.command, modifiers.shift, cx);
hover_at(editor, None, cx); hover_at(editor, None, cx);
gutter_hovered && was_top if gutter_hovered && was_top {
cx.stop_propagation();
}
} }
} }
@ -576,9 +578,9 @@ impl EditorElement {
position_map: &PositionMap, position_map: &PositionMap,
bounds: &InteractiveBounds, bounds: &InteractiveBounds,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> bool { ) {
if !bounds.visibly_contains(&event.position, cx) { if !bounds.visibly_contains(&event.position, cx) {
return false; return;
} }
let line_height = position_map.line_height; let line_height = position_map.line_height;
@ -602,8 +604,7 @@ impl EditorElement {
let y = f32::from((scroll_position.y * line_height - delta.y) / line_height); let y = f32::from((scroll_position.y * line_height - delta.y) / line_height);
let scroll_position = point(x, y).clamp(&point(0., 0.), &position_map.scroll_max); let scroll_position = point(x, y).clamp(&point(0., 0.), &position_map.scroll_max);
editor.scroll(scroll_position, axis, cx); editor.scroll(scroll_position, axis, cx);
cx.stop_propagation();
true
} }
fn paint_background( fn paint_background(
@ -2438,12 +2439,9 @@ impl EditorElement {
return; return;
} }
let handled = editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
Self::scroll(editor, event, &position_map, &interactive_bounds, cx) Self::scroll(editor, event, &position_map, &interactive_bounds, cx)
}); });
if handled {
cx.stop_propagation();
}
} }
}); });
@ -2457,7 +2455,7 @@ impl EditorElement {
return; return;
} }
let handled = match event.button { match event.button {
MouseButton::Left => editor.update(cx, |editor, cx| { MouseButton::Left => editor.update(cx, |editor, cx| {
Self::mouse_left_down( Self::mouse_left_down(
editor, editor,
@ -2472,12 +2470,8 @@ impl EditorElement {
MouseButton::Right => editor.update(cx, |editor, cx| { MouseButton::Right => editor.update(cx, |editor, cx| {
Self::mouse_right_down(editor, event, &position_map, text_bounds, cx) Self::mouse_right_down(editor, event, &position_map, text_bounds, cx)
}), }),
_ => false, _ => {}
}; };
if handled {
cx.stop_propagation()
}
} }
}); });
@ -2487,7 +2481,7 @@ impl EditorElement {
let stacking_order = cx.stacking_order().clone(); let stacking_order = cx.stacking_order().clone();
move |event: &MouseUpEvent, phase, cx| { move |event: &MouseUpEvent, phase, cx| {
let handled = editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
Self::mouse_up( Self::mouse_up(
editor, editor,
event, event,
@ -2497,10 +2491,6 @@ impl EditorElement {
cx, cx,
) )
}); });
if handled {
cx.stop_propagation()
}
} }
}); });
cx.on_mouse_event({ cx.on_mouse_event({
@ -2513,7 +2503,7 @@ impl EditorElement {
return; return;
} }
let stop_propogating = editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
Self::mouse_moved( Self::mouse_moved(
editor, editor,
event, event,
@ -2524,10 +2514,6 @@ impl EditorElement {
cx, cx,
) )
}); });
if stop_propogating {
cx.stop_propagation()
}
} }
}); });
} }