vim: Allow count and repeat for "r" and "shift-r" action (#13287)
Fixing the "r" action just involved adapting `normal_replace` to replace multiple characters. Fixing the "shift-r" command was less straightforward. The bindings for `vim::BeforeNormal` in replace mode were being overwritten and several other steps required for action repetition were not performed. Finally, the cursor adjustment after re-entering normal mode was duplicated (`vim::BeforeNormal` was now triggered correctly) so I removed the special case for replace mode. Release Notes: - Fixed vim "r" action to accept a count argument - Fixed vim "shift-r" action to accept a count argument and allow repetition --------- Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
This commit is contained in:
parent
77b2da2b42
commit
dea928b00c
8 changed files with 109 additions and 10 deletions
|
@ -16,6 +16,7 @@ pub fn register(workspace: &mut Workspace, _: &mut ViewContext<Workspace>) {
|
|||
workspace.register_action(|_, _: &ToggleReplace, cx: &mut ViewContext<Workspace>| {
|
||||
Vim::update(cx, |vim, cx| {
|
||||
vim.update_state(|state| state.replacements = vec![]);
|
||||
vim.start_recording(cx);
|
||||
vim.switch_mode(Mode::Replace, false, cx);
|
||||
});
|
||||
});
|
||||
|
@ -237,6 +238,30 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_replace_mode_with_counts(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx: NeovimBackedTestContext = NeovimBackedTestContext::new(cx).await;
|
||||
|
||||
cx.set_shared_state("ˇhello\n").await;
|
||||
cx.simulate_shared_keystrokes("3 shift-r - escape").await;
|
||||
cx.shared_state().await.assert_eq("--ˇ-lo\n");
|
||||
|
||||
cx.set_shared_state("ˇhello\n").await;
|
||||
cx.simulate_shared_keystrokes("3 shift-r a b c escape")
|
||||
.await;
|
||||
cx.shared_state().await.assert_eq("abcabcabˇc\n");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_replace_mode_repeat(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx: NeovimBackedTestContext = NeovimBackedTestContext::new(cx).await;
|
||||
|
||||
cx.set_shared_state("ˇhello world\n").await;
|
||||
cx.simulate_shared_keystrokes("shift-r - - - escape 4 l .")
|
||||
.await;
|
||||
cx.shared_state().await.assert_eq("---lo --ˇ-ld\n");
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn test_replace_mode_undo(cx: &mut gpui::TestAppContext) {
|
||||
let mut cx: NeovimBackedTestContext = NeovimBackedTestContext::new(cx).await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue