Fix panic when doing various cursor movements with a pending mouse selection (#13016)

This fixes a panic in the `SelectionsCollection::first_anchor` when
there was a pending mouse selection and no other selections. Until
recently, this method was only used in vim mode, but as of
53b0720d54,
it's also used in the normal `move_up` and `move_down` actions.

So until recently, the panic that this fixes could only happen in vim
mode.

Release Notes:

- Fixed a crash that could happen when using certain cursor-motion
bindings with a pending mouse selection.
This commit is contained in:
Max Brunsfeld 2024-06-13 16:22:45 -07:00 committed by GitHub
parent 01ba1ddef7
commit 066cdc2297
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 1 deletions

View file

@ -256,7 +256,10 @@ impl SelectionsCollection {
}
pub fn first_anchor(&self) -> Selection<Anchor> {
self.disjoint[0].clone()
self.pending
.as_ref()
.map(|pending| pending.selection.clone())
.unwrap_or_else(|| self.disjoint.first().cloned().unwrap())
}
pub fn first<D: TextDimension + Ord + Sub<D, Output = D>>(