Move selection helpers to SelectionCollection, add update_anchor_selections, add a number of invariant preserving mutation functions to the MutableSelectionCollection

This commit is contained in:
Keith Simmons 2022-05-05 21:09:26 -07:00
parent 61b4a4202f
commit c9dcfff607
22 changed files with 1891 additions and 1467 deletions

View file

@ -417,8 +417,11 @@ impl ProjectDiagnosticsEditor {
}];
} else {
groups = self.path_states.get(path_ix)?.diagnostic_groups.as_slice();
new_excerpt_ids_by_selection_id = editor.refresh_selections(cx);
selections = editor.local_selections::<usize>(cx);
new_excerpt_ids_by_selection_id =
editor.change_selections(true, cx, |s| s.refresh());
selections = editor
.selections
.interleaved::<usize>(&editor.buffer().read(cx).read(cx));
}
// If any selection has lost its position, move it to start of the next primary diagnostic.
@ -441,7 +444,9 @@ impl ProjectDiagnosticsEditor {
}
}
}
editor.update_selections(selections, None, cx);
editor.change_selections(true, cx, |s| {
s.select(selections, None);
});
Some(())
});

View file

@ -58,9 +58,7 @@ impl DiagnosticIndicator {
fn update(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
let editor = editor.read(cx);
let buffer = editor.buffer().read(cx);
let cursor_position = editor
.newest_selection_with_snapshot::<usize>(&buffer.read(cx))
.head();
let cursor_position = editor.selections.newest::<usize>(&buffer.read(cx)).head();
let new_diagnostic = buffer
.read(cx)
.diagnostics_in_range::<_, usize>(cursor_position..cursor_position, false)