Handle MouseUpEvent in editor2

This commit is contained in:
Antonio Scandurra 2023-11-08 15:17:30 +01:00
parent e500c05880
commit dfc536b4f5

View file

@ -4,7 +4,8 @@ use crate::{
git::{diff_hunk_to_display, DisplayDiffHunk}, git::{diff_hunk_to_display, DisplayDiffHunk},
hover_popover::hover_at, hover_popover::hover_at,
link_go_to_definition::{ link_go_to_definition::{
update_go_to_definition_link, update_inlay_link_and_hover_points, GoToDefinitionTrigger, go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link,
update_inlay_link_and_hover_points, GoToDefinitionTrigger,
}, },
scroll::scroll_amount::ScrollAmount, scroll::scroll_amount::ScrollAmount,
CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, CursorShape, DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle,
@ -17,9 +18,9 @@ use gpui::{
black, hsla, point, px, relative, size, transparent_black, Action, AnyElement, black, hsla, point, px, relative, size, transparent_black, Action, AnyElement,
BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase, BorrowAppContext, BorrowWindow, Bounds, ContentMask, Corners, DispatchContext, DispatchPhase,
Edges, Element, ElementId, Entity, GlobalElementId, Hsla, KeyDownEvent, KeyListener, KeyMatch, Edges, Element, ElementId, Entity, GlobalElementId, Hsla, KeyDownEvent, KeyListener, KeyMatch,
Line, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, Pixels, ScrollWheelEvent, Line, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle, TextSystem, ViewContext, ScrollWheelEvent, ShapedGlyph, Size, StatefulInteraction, Style, TextRun, TextStyle,
WindowContext, TextSystem, ViewContext, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use language::language_settings::ShowWhitespaceSetting; use language::language_settings::ShowWhitespaceSetting;
@ -312,37 +313,38 @@ impl EditorElement {
// true // true
// } // }
// fn mouse_up( fn mouse_up(
// editor: &mut Editor, editor: &mut Editor,
// position: gpui::Point<Pixels>, event: &MouseUpEvent,
// cmd: bool, position_map: &PositionMap,
// shift: bool, text_bounds: Bounds<Pixels>,
// alt: bool, cx: &mut ViewContext<Editor>,
// position_map: &PositionMap, ) -> bool {
// text_bounds: Bounds<Pixels>, let end_selection = editor.has_pending_selection();
// cx: &mut EventContext<Editor>, let pending_nonempty_selections = editor.has_pending_nonempty_selection();
// ) -> bool {
// let end_selection = editor.has_pending_selection();
// let pending_nonempty_selections = editor.has_pending_nonempty_selection();
// if end_selection { if end_selection {
// editor.select(SelectPhase::End, cx); editor.select(SelectPhase::End, cx);
// } }
// if !pending_nonempty_selections && cmd && text_bounds.contains_point(position) { if !pending_nonempty_selections
// let point = position_map.point_for_position(text_bounds, position); && event.modifiers.command
// let could_be_inlay = point.as_valid().is_none(); && text_bounds.contains_point(&event.position)
// if shift || could_be_inlay { {
// go_to_fetched_type_definition(editor, point, alt, cx); let point = position_map.point_for_position(text_bounds, event.position);
// } else { let could_be_inlay = point.as_valid().is_none();
// go_to_fetched_definition(editor, point, alt, cx); let split = event.modifiers.alt;
// } if event.modifiers.shift || could_be_inlay {
go_to_fetched_type_definition(editor, point, split, cx);
} else {
go_to_fetched_definition(editor, point, split, cx);
}
// return true; return true;
// } }
// end_selection end_selection
// } }
fn mouse_moved( fn mouse_moved(
editor: &mut Editor, editor: &mut Editor,
@ -2315,18 +2317,6 @@ impl EditorElement {
} }
} }
}); });
cx.on_mouse_event({
let position_map = position_map.clone();
move |editor, event: &MouseMoveEvent, phase, cx| {
if phase != DispatchPhase::Bubble {
return;
}
if Self::mouse_moved(editor, event, &position_map, text_bounds, cx) {
cx.stop_propagation()
}
}
});
cx.on_mouse_event({ cx.on_mouse_event({
let position_map = position_map.clone(); let position_map = position_map.clone();
move |editor, event: &MouseDownEvent, phase, cx| { move |editor, event: &MouseDownEvent, phase, cx| {
@ -2339,6 +2329,31 @@ impl EditorElement {
} }
} }
}); });
cx.on_mouse_event({
let position_map = position_map.clone();
move |editor, event: &MouseUpEvent, phase, cx| {
if phase != DispatchPhase::Bubble {
return;
}
if Self::mouse_up(editor, event, &position_map, text_bounds, cx) {
cx.stop_propagation()
}
}
});
cx.on_mouse_event({
let position_map = position_map.clone();
move |editor, event: &MouseMoveEvent, phase, cx| {
if phase != DispatchPhase::Bubble {
return;
}
if Self::mouse_moved(editor, event, &position_map, text_bounds, cx) {
cx.stop_propagation()
}
}
});
} }
} }