Skip to content

Commit

Permalink
Reset vimState.actionsCount when <C-o> pressed in insert mode (#4849)
Browse files Browse the repository at this point in the history
Fixes #4841

The existing implementation did not reset vimState.actionsCount when we perform action that put user in insert mode after pressing <C-o>
  • Loading branch information
fatanugraha committed May 14, 2020
1 parent f2f30e4 commit 4ec5e10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/actions/commands/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class CommandEscInsertMode extends BaseCommand {
// If we wanted to repeat this insert (only for i and a), now is the time to do it. Insert
// count amount of these strings before returning back to normal mode
const typeOfInsert =
vimState.recordedState.actionsRun[vimState.recordedState.actionsRun.length - 3];
vimState.recordedState.actionsRun[vimState.recordedState.actionsRun.length - 3];
const isTypeToRepeatInsert =
typeOfInsert instanceof CommandInsertAtCursor ||
typeOfInsert instanceof CommandInsertAfterCursor ||
Expand Down Expand Up @@ -437,6 +437,7 @@ export class CommandOneNormalCommandInInsertMode extends BaseCommand {

public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.returnToInsertAfterCommand = true;
vimState.actionCount = 0;
return new CommandEscInsertMode().exec(position, vimState);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ export class ModeHandler implements vscode.Disposable {
// Return to insert mode after 1 command in this case for <C-o>
if (vimState.returnToInsertAfterCommand) {
if (vimState.actionCount > 0) {
vimState.actionCount = 0;
await this.setCurrentMode(Mode.Insert);
} else {
vimState.actionCount++;
Expand Down
8 changes: 8 additions & 0 deletions test/mode/modeInsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ suite('Mode Insert', () => {
end: ['123|testtest123'],
});

newTest({
title: 'Can <ctrl-o> after entering insert mode from <ctrl-o>',
start: ['|'],
keysPressed: 'i<C-o>i<C-o>',
end: ['|'],
endMode: Mode.Normal
});

newTest({
title:
'Can perform <ctrl+o> to exit and perform one command in normal at the beginning of a row',
Expand Down

0 comments on commit 4ec5e10

Please sign in to comment.