fix splitting and combining cursors

This commit is contained in:
alice pellerin
2026-04-13 02:05:13 -05:00
parent 901350508d
commit 3e24d00af4
2 changed files with 18 additions and 4 deletions
+15 -3
View File
@@ -150,6 +150,8 @@ impl Buffer {
assert!(self.scroll_position <= self.primary_cursor.head);
assert!(self.primary_cursor.head < self.scroll_position + window_size.visible_byte_count());
debug_assert!(self.cursors.is_sorted_by_key(|cursor| cursor.head));
app_action
}
@@ -309,10 +311,20 @@ impl Buffer {
pub fn combine_cursors_if_overlapping(&mut self) {
let mut index = 0;
// TODO: this can miss some in the WEIRD case that
// [ *]
// [ *]
// [ *]
// where * is the head.
// the first one wont merge with the 2nd, but the 2nd will
// merge with the 3rd, which would then overlap with the 1st,
// but won't be checked
while !self.cursors.is_empty() && index < self.cursors.len() {
while index < self.cursors.len() - 1 &&
self.cursors[index].range().is_overlapping(
&self.cursors[index + 1].range())
&self.cursors[index + 1].range()
)
{
let next_cursor = self.cursors[index + 1];
self.cursors[index].combine_with(next_cursor);
@@ -324,11 +336,11 @@ impl Buffer {
{
self.primary_cursor.combine_with(self.cursors[index]);
self.cursors.remove(index);
}
} else {
index += 1;
}
}
}
}
fn nybble_from_hex(hex: char) -> Option<u8> {
+3 -1
View File
@@ -425,7 +425,9 @@ impl Buffer {
});
self.primary_cursor = new_cursors.next().unwrap();
self.cursors = new_cursors.collect();
self.cursors = new_cursors
.sorted_by_key(|cursor| cursor.head)
.collect();
self.clamp_screen_to_primary_cursor(window_size);
}