This commit is contained in:
Viet-Hoa Do 2025-08-26 09:41:59 -04:00 committed by GitHub
commit 35ba54c33f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 80 additions and 18 deletions

View file

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

View file

@ -10131,6 +10131,7 @@ pub fn register_action<T: Action>(
if phase == DispatchPhase::Bubble { if phase == DispatchPhase::Bubble {
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
listener(editor, action, window, cx); listener(editor, action, window, cx);
editor.reset_mark(window, cx);
}) })
} }
}) })