Ensure there's at least one selection in Editor::set_selections
This commit introduces an assertion that will cause Zed to panic as soon as the invariant gets violated. This will be useful to investigate issue #503. Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
parent
be3bfb2699
commit
a3ea6a34d9
2 changed files with 7 additions and 1 deletions
|
@ -4992,6 +4992,11 @@ impl Editor {
|
||||||
pending_selection: Option<PendingSelection>,
|
pending_selection: Option<PendingSelection>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
|
assert!(
|
||||||
|
!selections.is_empty() || pending_selection.is_some(),
|
||||||
|
"must have at least one selection"
|
||||||
|
);
|
||||||
|
|
||||||
let old_cursor_position = self.newest_anchor_selection().head();
|
let old_cursor_position = self.newest_anchor_selection().head();
|
||||||
|
|
||||||
self.selections = selections;
|
self.selections = selections;
|
||||||
|
|
|
@ -3357,7 +3357,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
40..=44 if !anchors.is_empty() => {
|
40..=44 if !anchors.is_empty() => {
|
||||||
let multibuffer = multibuffer.read(cx).read(cx);
|
let multibuffer = multibuffer.read(cx).read(cx);
|
||||||
|
let prev_len = anchors.len();
|
||||||
anchors = multibuffer
|
anchors = multibuffer
|
||||||
.refresh_anchors(&anchors)
|
.refresh_anchors(&anchors)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -3366,6 +3366,7 @@ mod tests {
|
||||||
|
|
||||||
// Ensure the newly-refreshed anchors point to a valid excerpt and don't
|
// Ensure the newly-refreshed anchors point to a valid excerpt and don't
|
||||||
// overshoot its boundaries.
|
// overshoot its boundaries.
|
||||||
|
assert_eq!(anchors.len(), prev_len);
|
||||||
let mut cursor = multibuffer.excerpts.cursor::<Option<&ExcerptId>>();
|
let mut cursor = multibuffer.excerpts.cursor::<Option<&ExcerptId>>();
|
||||||
for anchor in &anchors {
|
for anchor in &anchors {
|
||||||
if anchor.excerpt_id == ExcerptId::min()
|
if anchor.excerpt_id == ExcerptId::min()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue