remove primary selection

This commit is contained in:
alice pellerin
2026-03-21 00:26:18 -05:00
parent e0b3bbe052
commit fdd9ddd6ff
2 changed files with 18 additions and 0 deletions
+16
View File
@@ -67,6 +67,7 @@ pub enum Action {
RotateSelectionsForward,
KeepPrimarySelection,
RemovePrimarySelection,
}
// actions that act on the app as a whole, not just one buffer
@@ -145,6 +146,7 @@ impl Buffer {
Action::RotateSelectionsForward => self.rotate_selections_forward(),
Action::KeepPrimarySelection => self.keep_primary_selection(),
Action::RemovePrimarySelection => self.remove_primary_selection(),
}
None
@@ -532,6 +534,20 @@ impl Buffer {
fn keep_primary_selection(&mut self) {
self.cursors.clear();
}
fn remove_primary_selection(&mut self) {
if self.cursors.is_empty() { return; }
let next_cursor_index = self.cursors
.binary_search_by_key(&self.primary_cursor.head, |cursor| cursor.head)
.unwrap_or_else(identity);
if next_cursor_index == self.cursors.len() {
self.primary_cursor = self.cursors.remove(0);
} else {
self.primary_cursor = self.cursors.remove(next_cursor_index);
}
}
}
// helpers