Remove Select internal action

This commit is contained in:
Antonio Scandurra 2023-04-28 12:33:22 +02:00
parent 5215adbd3f
commit a978f3fe4f
3 changed files with 54 additions and 45 deletions

View file

@ -104,9 +104,6 @@ pub struct SelectNext {
pub replace_newest: bool, pub replace_newest: bool,
} }
#[derive(Clone, PartialEq)]
pub struct Select(pub SelectPhase);
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub struct Jump { pub struct Jump {
path: ProjectPath, path: ProjectPath,
@ -285,7 +282,7 @@ impl_actions!(
] ]
); );
impl_internal_actions!(editor, [Select, Jump]); impl_internal_actions!(editor, [Jump]);
enum DocumentHighlightRead {} enum DocumentHighlightRead {}
enum DocumentHighlightWrite {} enum DocumentHighlightWrite {}
@ -299,7 +296,6 @@ pub enum Direction {
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.add_action(Editor::new_file); cx.add_action(Editor::new_file);
cx.add_action(Editor::select);
cx.add_action(Editor::cancel); cx.add_action(Editor::cancel);
cx.add_action(Editor::newline); cx.add_action(Editor::newline);
cx.add_action(Editor::newline_above); cx.add_action(Editor::newline_above);
@ -1562,7 +1558,7 @@ impl Editor {
}); });
} }
fn select(&mut self, Select(phase): &Select, cx: &mut ViewContext<Self>) { fn select(&mut self, phase: SelectPhase, cx: &mut ViewContext<Self>) {
self.hide_context_menu(cx); self.hide_context_menu(cx);
match phase { match phase {
@ -1570,20 +1566,20 @@ impl Editor {
position, position,
add, add,
click_count, click_count,
} => self.begin_selection(*position, *add, *click_count, cx), } => self.begin_selection(position, add, click_count, cx),
SelectPhase::BeginColumnar { SelectPhase::BeginColumnar {
position, position,
goal_column, goal_column,
} => self.begin_columnar_selection(*position, *goal_column, cx), } => self.begin_columnar_selection(position, goal_column, cx),
SelectPhase::Extend { SelectPhase::Extend {
position, position,
click_count, click_count,
} => self.extend_selection(*position, *click_count, cx), } => self.extend_selection(position, click_count, cx),
SelectPhase::Update { SelectPhase::Update {
position, position,
goal_column, goal_column,
scroll_position, scroll_position,
} => self.update_selection(*position, *goal_column, *scroll_position, cx), } => self.update_selection(position, goal_column, scroll_position, cx),
SelectPhase::End => self.end_selection(cx), SelectPhase::End => self.end_selection(cx),
} }
} }

View file

@ -1,7 +1,7 @@
use super::{ use super::{
display_map::{BlockContext, ToDisplayPoint}, display_map::{BlockContext, ToDisplayPoint},
Anchor, DisplayPoint, Editor, EditorMode, EditorSnapshot, Select, SelectPhase, SoftWrap, Anchor, DisplayPoint, Editor, EditorMode, EditorSnapshot, SelectPhase, SoftWrap, ToPoint,
ToPoint, MAX_LINE_LEN, MAX_LINE_LEN,
}; };
use crate::{ use crate::{
display_map::{BlockStyle, DisplaySnapshot, FoldStatus, TransformBlock}, display_map::{BlockStyle, DisplaySnapshot, FoldStatus, TransformBlock},
@ -115,9 +115,10 @@ impl EditorElement {
) )
.on_down(MouseButton::Left, { .on_down(MouseButton::Left, {
let position_map = position_map.clone(); let position_map = position_map.clone();
move |e, _, cx| { move |event, editor, cx| {
if !Self::mouse_down( if !Self::mouse_down(
e.platform_event, editor,
event.platform_event,
position_map.as_ref(), position_map.as_ref(),
text_bounds, text_bounds,
gutter_bounds, gutter_bounds,
@ -129,7 +130,7 @@ impl EditorElement {
}) })
.on_down(MouseButton::Right, { .on_down(MouseButton::Right, {
let position_map = position_map.clone(); let position_map = position_map.clone();
move |event, _, cx| { move |event, _editor, cx| {
if !Self::mouse_right_down( if !Self::mouse_right_down(
event.position, event.position,
position_map.as_ref(), position_map.as_ref(),
@ -144,12 +145,12 @@ impl EditorElement {
let position_map = position_map.clone(); let position_map = position_map.clone();
move |event, editor, cx| { move |event, editor, cx| {
if !Self::mouse_up( if !Self::mouse_up(
editor,
event.position, event.position,
event.cmd, event.cmd,
event.shift, event.shift,
position_map.as_ref(), position_map.as_ref(),
text_bounds, text_bounds,
editor,
cx, cx,
) { ) {
cx.propagate_event() cx.propagate_event()
@ -160,10 +161,10 @@ impl EditorElement {
let position_map = position_map.clone(); let position_map = position_map.clone();
move |event, editor, cx| { move |event, editor, cx| {
if !Self::mouse_dragged( if !Self::mouse_dragged(
editor,
event.platform_event, event.platform_event,
position_map.as_ref(), position_map.as_ref(),
text_bounds, text_bounds,
editor,
cx, cx,
) { ) {
cx.propagate_event() cx.propagate_event()
@ -172,8 +173,8 @@ impl EditorElement {
}) })
.on_move({ .on_move({
let position_map = position_map.clone(); let position_map = position_map.clone();
move |e, _, cx| { move |event, _editor, cx| {
if !Self::mouse_moved(e.platform_event, &position_map, text_bounds, cx) { if !Self::mouse_moved(event.platform_event, &position_map, text_bounds, cx) {
cx.propagate_event() cx.propagate_event()
} }
} }
@ -212,6 +213,7 @@ impl EditorElement {
} }
fn mouse_down( fn mouse_down(
editor: &mut Editor,
MouseButtonEvent { MouseButtonEvent {
position, position,
modifiers: modifiers:
@ -239,21 +241,30 @@ impl EditorElement {
let (position, target_position) = position_map.point_for_position(text_bounds, position); let (position, target_position) = position_map.point_for_position(text_bounds, position);
if shift && alt { if shift && alt {
cx.dispatch_action(Select(SelectPhase::BeginColumnar { editor.select(
SelectPhase::BeginColumnar {
position, position,
goal_column: target_position.column(), goal_column: target_position.column(),
})); },
cx,
);
} else if shift && !ctrl && !alt && !cmd { } else if shift && !ctrl && !alt && !cmd {
cx.dispatch_action(Select(SelectPhase::Extend { editor.select(
SelectPhase::Extend {
position, position,
click_count, click_count,
})); },
cx,
);
} else { } else {
cx.dispatch_action(Select(SelectPhase::Begin { editor.select(
SelectPhase::Begin {
position, position,
add: alt, add: alt,
click_count, click_count,
})); },
cx,
);
} }
true true
@ -276,19 +287,19 @@ impl EditorElement {
} }
fn mouse_up( fn mouse_up(
editor: &mut Editor,
position: Vector2F, position: Vector2F,
cmd: bool, cmd: bool,
shift: bool, shift: bool,
position_map: &PositionMap, position_map: &PositionMap,
text_bounds: RectF, text_bounds: RectF,
editor: &mut Editor,
cx: &mut EventContext<Editor>, cx: &mut EventContext<Editor>,
) -> bool { ) -> 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();
if end_selection { if end_selection {
cx.dispatch_action(Select(SelectPhase::End)); editor.select(SelectPhase::End, cx);
} }
if !pending_nonempty_selections && cmd && text_bounds.contains_point(position) { if !pending_nonempty_selections && cmd && text_bounds.contains_point(position) {
@ -309,6 +320,7 @@ impl EditorElement {
} }
fn mouse_dragged( fn mouse_dragged(
editor: &mut Editor,
MouseMovedEvent { MouseMovedEvent {
modifiers: Modifiers { cmd, shift, .. }, modifiers: Modifiers { cmd, shift, .. },
position, position,
@ -316,7 +328,6 @@ impl EditorElement {
}: MouseMovedEvent, }: MouseMovedEvent,
position_map: &PositionMap, position_map: &PositionMap,
text_bounds: RectF, text_bounds: RectF,
editor: &mut Editor,
cx: &mut EventContext<Editor>, cx: &mut EventContext<Editor>,
) -> bool { ) -> bool {
// This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed // This will be handled more correctly once https://github.com/zed-industries/zed/issues/1218 is completed
@ -368,12 +379,15 @@ impl EditorElement {
let (position, target_position) = let (position, target_position) =
position_map.point_for_position(text_bounds, position); position_map.point_for_position(text_bounds, position);
cx.dispatch_action(Select(SelectPhase::Update { editor.select(
SelectPhase::Update {
position, position,
goal_column: target_position.column(), goal_column: target_position.column(),
scroll_position: (position_map.snapshot.scroll_position() + scroll_delta) scroll_position: (position_map.snapshot.scroll_position() + scroll_delta)
.clamp(Vector2F::zero(), position_map.scroll_max), .clamp(Vector2F::zero(), position_map.scroll_max),
})); },
cx,
);
cx.dispatch_action(HoverAt { point }); cx.dispatch_action(HoverAt { point });
true true

View file

@ -8,8 +8,7 @@ use util::TryFutureExt;
use workspace::Workspace; use workspace::Workspace;
use crate::{ use crate::{
Anchor, DisplayPoint, Editor, EditorSnapshot, GoToDefinition, GoToTypeDefinition, Select, Anchor, DisplayPoint, Editor, EditorSnapshot, GoToDefinition, GoToTypeDefinition, SelectPhase,
SelectPhase,
}; };
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]
@ -334,11 +333,11 @@ fn go_to_fetched_definition_of_kind(
} else { } else {
editor_handle.update(cx, |editor, cx| { editor_handle.update(cx, |editor, cx| {
editor.select( editor.select(
&Select(SelectPhase::Begin { SelectPhase::Begin {
position: point, position: point,
add: false, add: false,
click_count: 1, click_count: 1,
}), },
cx, cx,
); );
}); });