diff --git a/src/action.rs b/src/action.rs index c6b4b35..46c7c8e 100644 --- a/src/action.rs +++ b/src/action.rs @@ -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 diff --git a/src/config.rs b/src/config.rs index a1de155..41115d8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -148,6 +148,7 @@ impl Default for Config { (")".try_into().unwrap(), Action::RotateSelectionsForward), (",".try_into().unwrap(), Action::KeepPrimarySelection), + ("A-,".try_into().unwrap(), Action::RemovePrimarySelection), ].into()), (Some(PartialAction::Goto), [ ("j".try_into().unwrap(), Action::GotoLineStart), @@ -205,6 +206,7 @@ impl Default for Config { (")".try_into().unwrap(), Action::RotateSelectionsForward), (",".try_into().unwrap(), Action::KeepPrimarySelection), + ("A-,".try_into().unwrap(), Action::RemovePrimarySelection), ].into()), (Some(PartialAction::Space), [ ("w".try_into().unwrap(), Action::Save),