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, RotateSelectionsForward,
KeepPrimarySelection, KeepPrimarySelection,
RemovePrimarySelection,
} }
// actions that act on the app as a whole, not just one buffer // 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::RotateSelectionsForward => self.rotate_selections_forward(),
Action::KeepPrimarySelection => self.keep_primary_selection(), Action::KeepPrimarySelection => self.keep_primary_selection(),
Action::RemovePrimarySelection => self.remove_primary_selection(),
} }
None None
@@ -532,6 +534,20 @@ impl Buffer {
fn keep_primary_selection(&mut self) { fn keep_primary_selection(&mut self) {
self.cursors.clear(); 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 // helpers
+2
View File
@@ -148,6 +148,7 @@ impl Default for Config {
(")".try_into().unwrap(), Action::RotateSelectionsForward), (")".try_into().unwrap(), Action::RotateSelectionsForward),
(",".try_into().unwrap(), Action::KeepPrimarySelection), (",".try_into().unwrap(), Action::KeepPrimarySelection),
("A-,".try_into().unwrap(), Action::RemovePrimarySelection),
].into()), ].into()),
(Some(PartialAction::Goto), [ (Some(PartialAction::Goto), [
("j".try_into().unwrap(), Action::GotoLineStart), ("j".try_into().unwrap(), Action::GotoLineStart),
@@ -205,6 +206,7 @@ impl Default for Config {
(")".try_into().unwrap(), Action::RotateSelectionsForward), (")".try_into().unwrap(), Action::RotateSelectionsForward),
(",".try_into().unwrap(), Action::KeepPrimarySelection), (",".try_into().unwrap(), Action::KeepPrimarySelection),
("A-,".try_into().unwrap(), Action::RemovePrimarySelection),
].into()), ].into()),
(Some(PartialAction::Space), [ (Some(PartialAction::Space), [
("w".try_into().unwrap(), Action::Save), ("w".try_into().unwrap(), Action::Save),