editor: Assert ordering in selections of resolve_selections (#38861)

Inspired by the recent anchor assertions, this asserts that the produced
selections are always ordered at various resolutions stages, this is an
invariant within `SelectionsCollection` but something breaks it
somewhere causing us to seek cursors backwards which panics.

Related to ZED-13X

Release Notes:

- N/A
This commit is contained in:
Lukas Wirth
2025-09-25 10:06:47 +00:00
committed by GitHub
parent a25504edaf
commit 16fccb5c76
8 changed files with 108 additions and 58 deletions
+4 -2
View File
@@ -822,7 +822,7 @@ impl Vim {
editor.set_collapse_matches(false);
editor.set_input_enabled(true);
editor.set_autoindent(true);
editor.selections.line_mode = false;
editor.selections.set_line_mode(false);
editor.unregister_addon::<VimAddon>();
editor.set_relative_line_number(None, cx);
if let Some(vim) = Vim::globals(cx).focused_vim()
@@ -1787,7 +1787,9 @@ impl Vim {
editor.set_collapse_matches(true);
editor.set_input_enabled(vim.editor_input_enabled());
editor.set_autoindent(vim.should_autoindent());
editor.selections.line_mode = matches!(vim.mode, Mode::VisualLine);
editor
.selections
.set_line_mode(matches!(vim.mode, Mode::VisualLine));
let hide_edit_predictions = !matches!(vim.mode, Mode::Insert | Mode::Replace);
editor.set_edit_predictions_hidden_for_vim_mode(hide_edit_predictions, window, cx);
+4 -4
View File
@@ -609,8 +609,8 @@ impl Vim {
self.store_visual_marks(window, cx);
self.update_editor(cx, |vim, editor, cx| {
let mut original_columns: HashMap<_, _> = Default::default();
let line_mode = line_mode || editor.selections.line_mode;
editor.selections.line_mode = false;
let line_mode = line_mode || editor.selections.line_mode();
editor.selections.set_line_mode(false);
editor.transact(window, cx, |editor, window, cx| {
editor.change_selections(Default::default(), window, cx, |s| {
@@ -692,7 +692,7 @@ impl Vim {
pub fn visual_yank(&mut self, line_mode: bool, window: &mut Window, cx: &mut Context<Self>) {
self.store_visual_marks(window, cx);
self.update_editor(cx, |vim, editor, cx| {
let line_mode = line_mode || editor.selections.line_mode;
let line_mode = line_mode || editor.selections.line_mode();
// For visual line mode, adjust selections to avoid yanking the next line when on \n
if line_mode && vim.mode != Mode::VisualBlock {
@@ -710,7 +710,7 @@ impl Vim {
});
}
editor.selections.line_mode = line_mode;
editor.selections.set_line_mode(line_mode);
let kind = if line_mode {
MotionKind::Linewise
} else {