From ec4719146aad8f137a7754fb784bb0efbbf2bc59 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 4 Mar 2025 21:47:12 -0700 Subject: [PATCH] Fix . repeat for remapping surrounds/exchange actions (#26101) Closes #ISSUE cc @thomasheartman Release Notes: - vim: Fixes `.` repeat for remapped surrounds/exchange actions --- crates/vim/src/state.rs | 37 +++++++++++++++++++++++++++++++++++++ crates/vim/src/vim.rs | 22 +++------------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/crates/vim/src/state.rs b/crates/vim/src/state.rs index b5ce364ae0..bb0a3aebdb 100644 --- a/crates/vim/src/state.rs +++ b/crates/vim/src/state.rs @@ -561,4 +561,41 @@ impl Operator { | Operator::ToggleComments => false, } } + + pub fn starts_dot_recording(&self) -> bool { + match self { + Operator::Change + | Operator::Delete + | Operator::Replace + | Operator::Indent + | Operator::Outdent + | Operator::AutoIndent + | Operator::Lowercase + | Operator::Uppercase + | Operator::OppositeCase + | Operator::ToggleComments + | Operator::ReplaceWithRegister + | Operator::Rewrap + | Operator::ShellCommand + | Operator::AddSurrounds { target: None } + | Operator::ChangeSurrounds { target: None } + | Operator::DeleteSurrounds + | Operator::Exchange => true, + Operator::Yank + | Operator::Object { .. } + | Operator::FindForward { .. } + | Operator::FindBackward { .. } + | Operator::Sneak { .. } + | Operator::SneakBackward { .. } + | Operator::Mark + | Operator::Digraph { .. } + | Operator::Literal { .. } + | Operator::AddSurrounds { .. } + | Operator::ChangeSurrounds { .. } + | Operator::Jump { .. } + | Operator::Register + | Operator::RecordRegister + | Operator::ReplayRegister => false, + } + } } diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index efd80c9395..92610aa77d 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -827,22 +827,9 @@ impl Vim { } fn push_operator(&mut self, operator: Operator, window: &mut Window, cx: &mut Context) { - if matches!( - operator, - Operator::Change - | Operator::Delete - | Operator::Replace - | Operator::Indent - | Operator::Outdent - | Operator::AutoIndent - | Operator::Lowercase - | Operator::Uppercase - | Operator::OppositeCase - | Operator::ToggleComments - | Operator::ReplaceWithRegister - ) { - self.start_recording(cx) - }; + if operator.starts_dot_recording() { + self.start_recording(cx); + } // Since these operations can only be entered with pre-operators, // we need to clear the previous operators when pushing, // so that the current stack is the most correct @@ -853,9 +840,6 @@ impl Vim { | Operator::DeleteSurrounds ) { self.operator_stack.clear(); - if let Operator::AddSurrounds { target: None } = operator { - self.start_recording(cx); - } }; self.operator_stack.push(operator); self.sync_vim_settings(window, cx);