diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 29e009fdf8..3f610d0772 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1165,6 +1165,7 @@ pub struct Editor { /// Whether we are temporarily displaying a diff other than git's temporary_diff_override: bool, selection_mark_mode: bool, + continue_selection_mark_mode: bool, toggle_fold_multiple_buffers: Task<()>, _scroll_cursor_center_top_bottom_task: Task<()>, serialize_selections: Task<()>, @@ -2241,6 +2242,7 @@ impl Editor { registered_buffers: HashMap::default(), _scroll_cursor_center_top_bottom_task: Task::ready(()), selection_mark_mode: false, + continue_selection_mark_mode: false, toggle_fold_multiple_buffers: Task::ready(()), serialize_selections: Task::ready(()), serialize_folds: Task::ready(()), @@ -12407,7 +12409,9 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(|map, head, _| (movement::left(map, head), SelectionGoal::None)); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_right(&mut self, _: &MoveRight, window: &mut Window, cx: &mut Context) { @@ -12428,7 +12432,9 @@ impl Editor { self.hide_mouse_cursor(HideMouseCursorOrigin::MovementAction, cx); self.change_selections(Default::default(), window, cx, |s| { s.move_heads_with(|map, head, _| (movement::right(map, head), SelectionGoal::None)); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_up(&mut self, _: &MoveUp, window: &mut Window, cx: &mut Context) { @@ -12555,7 +12561,9 @@ impl Editor { s.move_heads_with(|map, head, goal| { movement::down_by_rows(map, head, action.lines, goal, false, text_layout_details) }) - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_up_by_lines( @@ -12570,7 +12578,9 @@ impl Editor { s.move_heads_with(|map, head, goal| { movement::up_by_rows(map, head, action.lines, goal, false, text_layout_details) }) - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_page_up( @@ -12591,7 +12601,9 @@ impl Editor { s.move_heads_with(|map, head, goal| { movement::up_by_rows(map, head, row_count, goal, false, text_layout_details) }) - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_page_up( @@ -12658,7 +12670,9 @@ impl Editor { s.move_heads_with(|map, head, goal| { movement::up(map, head, goal, false, text_layout_details) }) - }) + }); + + self.continue_selection_mark_mode = true; } pub fn move_down(&mut self, _: &MoveDown, window: &mut Window, cx: &mut Context) { @@ -12715,7 +12729,9 @@ impl Editor { s.move_heads_with(|map, head, goal| { movement::down_by_rows(map, head, row_count, goal, false, text_layout_details) }) - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_page_down( @@ -12782,6 +12798,8 @@ impl Editor { movement::down(map, head, goal, false, text_layout_details) }) }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn context_menu_first( @@ -12908,7 +12926,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_to_previous_subword_start( @@ -12925,7 +12945,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn delete_to_previous_word_start( @@ -13013,7 +13035,9 @@ impl Editor { s.move_heads_with(|map, head, _| { (movement::next_word_end(map, head), SelectionGoal::None) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_to_next_subword_end( @@ -13027,7 +13051,9 @@ impl Editor { s.move_heads_with(|map, head, _| { (movement::next_subword_end(map, head), SelectionGoal::None) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn delete_to_next_word_end( @@ -13116,6 +13142,8 @@ impl Editor { ) }); }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn delete_to_beginning_of_line( @@ -13175,7 +13203,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn delete_to_end_of_line( @@ -13276,7 +13306,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_to_end_of_paragraph( @@ -13297,7 +13329,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_to_start_of_excerpt( @@ -13418,7 +13452,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_to_start_of_next_excerpt( @@ -13439,7 +13475,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_to_end_of_excerpt( @@ -13460,7 +13498,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_to_end_of_previous_excerpt( @@ -13481,7 +13521,9 @@ impl Editor { SelectionGoal::None, ) }); - }) + }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_to_beginning( @@ -13512,6 +13554,8 @@ impl Editor { self.change_selections(Default::default(), window, cx, |s| { s.select(vec![selection]); }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn move_to_end(&mut self, _: &MoveToEnd, window: &mut Window, cx: &mut Context) { @@ -13590,6 +13634,8 @@ impl Editor { self.change_selections(Default::default(), window, cx, |s| { s.select(vec![selection]); }); + + self.continue_selection_mark_mode = self.selection_mark_mode; } pub fn select_all(&mut self, _: &SelectAll, window: &mut Window, cx: &mut Context) { @@ -17209,9 +17255,24 @@ impl Editor { }) } self.selection_mark_mode = true; + self.continue_selection_mark_mode = true; cx.notify(); } + pub fn reset_mark(&mut self, window: &mut Window, cx: &mut Context) { + if self.selection_mark_mode && !self.continue_selection_mark_mode { + self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| { + s.move_with(|_, sel| { + sel.collapse_to(sel.head(), SelectionGoal::None); + }); + }); + + self.selection_mark_mode = false; + } + + self.continue_selection_mark_mode = false; + } + pub fn swap_selection_ends( &mut self, _: &actions::SwapSelectionEnds, diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 4f3580da07..7356fc17ce 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -10131,6 +10131,7 @@ pub fn register_action( if phase == DispatchPhase::Bubble { editor.update(cx, |editor, cx| { listener(editor, action, window, cx); + editor.reset_mark(window, cx); }) } })