Merge pull request #1482 from zed-industries/click-goto-on-mouse-up
Handle Cmd/Shift + Click go-to action on mouse-up instead of mouse-down
This commit is contained in:
commit
635805cd6f
2 changed files with 47 additions and 36 deletions
|
@ -1787,6 +1787,14 @@ impl Editor {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn are_selections_empty(&self) -> bool {
|
||||||
|
let pending_empty = match self.selections.pending_anchor() {
|
||||||
|
Some(Selection { start, end, .. }) => start == end,
|
||||||
|
None => true,
|
||||||
|
};
|
||||||
|
pending_empty && self.columnar_selection_tail.is_none()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_selecting(&self) -> bool {
|
pub fn is_selecting(&self) -> bool {
|
||||||
self.selections.pending_anchor().is_some() || self.columnar_selection_tail.is_some()
|
self.selections.pending_anchor().is_some() || self.columnar_selection_tail.is_some()
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,6 @@ impl EditorElement {
|
||||||
fn mouse_down(
|
fn mouse_down(
|
||||||
&self,
|
&self,
|
||||||
position: Vector2F,
|
position: Vector2F,
|
||||||
cmd: bool,
|
|
||||||
alt: bool,
|
alt: bool,
|
||||||
shift: bool,
|
shift: bool,
|
||||||
mut click_count: usize,
|
mut click_count: usize,
|
||||||
|
@ -121,20 +120,6 @@ impl EditorElement {
|
||||||
paint: &mut PaintState,
|
paint: &mut PaintState,
|
||||||
cx: &mut EventContext,
|
cx: &mut EventContext,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if cmd && paint.text_bounds.contains_point(position) {
|
|
||||||
let (point, target_point) =
|
|
||||||
paint.point_for_position(&self.snapshot(cx), layout, position);
|
|
||||||
if point == target_point {
|
|
||||||
if shift {
|
|
||||||
cx.dispatch_action(GoToFetchedTypeDefinition { point });
|
|
||||||
} else {
|
|
||||||
cx.dispatch_action(GoToFetchedDefinition { point });
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if paint.gutter_bounds.contains_point(position) {
|
if paint.gutter_bounds.contains_point(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 !paint.text_bounds.contains_point(position) {
|
} else if !paint.text_bounds.contains_point(position) {
|
||||||
|
@ -183,13 +168,39 @@ impl EditorElement {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mouse_up(&self, _position: Vector2F, cx: &mut EventContext) -> bool {
|
fn mouse_up(
|
||||||
if self.view(cx.app.as_ref()).is_selecting() {
|
&self,
|
||||||
|
position: Vector2F,
|
||||||
|
cmd: bool,
|
||||||
|
shift: bool,
|
||||||
|
layout: &mut LayoutState,
|
||||||
|
paint: &mut PaintState,
|
||||||
|
cx: &mut EventContext,
|
||||||
|
) -> bool {
|
||||||
|
let view = self.view(cx.app.as_ref());
|
||||||
|
let end_selection = view.is_selecting();
|
||||||
|
let selections_empty = view.are_selections_empty();
|
||||||
|
|
||||||
|
if end_selection {
|
||||||
cx.dispatch_action(Select(SelectPhase::End));
|
cx.dispatch_action(Select(SelectPhase::End));
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if selections_empty && cmd && paint.text_bounds.contains_point(position) {
|
||||||
|
let (point, target_point) =
|
||||||
|
paint.point_for_position(&self.snapshot(cx), layout, position);
|
||||||
|
|
||||||
|
if point == target_point {
|
||||||
|
if shift {
|
||||||
|
cx.dispatch_action(GoToFetchedTypeDefinition { point });
|
||||||
|
} else {
|
||||||
|
cx.dispatch_action(GoToFetchedDefinition { point });
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end_selection
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mouse_dragged(
|
fn mouse_dragged(
|
||||||
|
@ -1533,36 +1544,28 @@ impl Element for EditorElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::MouseDown(MouseButtonEvent {
|
&Event::MouseDown(MouseButtonEvent {
|
||||||
button: MouseButton::Left,
|
button: MouseButton::Left,
|
||||||
position,
|
position,
|
||||||
cmd,
|
|
||||||
alt,
|
alt,
|
||||||
shift,
|
shift,
|
||||||
click_count,
|
click_count,
|
||||||
..
|
..
|
||||||
}) => self.mouse_down(
|
}) => self.mouse_down(position, alt, shift, click_count, layout, paint, cx),
|
||||||
*position,
|
|
||||||
*cmd,
|
|
||||||
*alt,
|
|
||||||
*shift,
|
|
||||||
*click_count,
|
|
||||||
layout,
|
|
||||||
paint,
|
|
||||||
cx,
|
|
||||||
),
|
|
||||||
|
|
||||||
Event::MouseDown(MouseButtonEvent {
|
&Event::MouseDown(MouseButtonEvent {
|
||||||
button: MouseButton::Right,
|
button: MouseButton::Right,
|
||||||
position,
|
position,
|
||||||
..
|
..
|
||||||
}) => self.mouse_right_down(*position, layout, paint, cx),
|
}) => self.mouse_right_down(position, layout, paint, cx),
|
||||||
|
|
||||||
Event::MouseUp(MouseButtonEvent {
|
&Event::MouseUp(MouseButtonEvent {
|
||||||
button: MouseButton::Left,
|
button: MouseButton::Left,
|
||||||
position,
|
position,
|
||||||
|
cmd,
|
||||||
|
shift,
|
||||||
..
|
..
|
||||||
}) => self.mouse_up(*position, cx),
|
}) => self.mouse_up(position, cmd, shift, layout, paint, cx),
|
||||||
|
|
||||||
Event::MouseMoved(MouseMovedEvent {
|
Event::MouseMoved(MouseMovedEvent {
|
||||||
pressed_button: Some(MouseButton::Left),
|
pressed_button: Some(MouseButton::Left),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue