Skip to content

Commit

Permalink
Merge pull request #1846 from xconverge/multipleAorI
Browse files Browse the repository at this point in the history
fixes #1843 A and I preceded by count
  • Loading branch information
xconverge authored Jun 16, 2017
2 parents fb9a634 + 44905e4 commit beead66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1974,7 +1974,7 @@ class CommandGoForwardInChangelist extends BaseCommand {
}

@RegisterAction
class CommandInsertAtFirstCharacter extends BaseCommand {
export class CommandInsertAtFirstCharacter extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual];
keys = ["I"];

Expand Down Expand Up @@ -2031,7 +2031,7 @@ export class CommandInsertAfterCursor extends BaseCommand {
}

@RegisterAction
class CommandInsertAtLineEnd extends BaseCommand {
export class CommandInsertAtLineEnd extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual];
keys = ["A"];

Expand Down
14 changes: 11 additions & 3 deletions src/actions/commands/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { TextEditor } from './../../textEditor';
import { RegisterAction } from './../base';
import { ArrowsInInsertMode } from './../motion';
import {
BaseCommand, DocumentContentChangeAction, CommandInsertAtCursor, CommandInsertAfterCursor
BaseCommand, DocumentContentChangeAction, CommandInsertAtCursor,
CommandInsertAfterCursor, CommandInsertAtLineEnd,
CommandInsertAtFirstCharacter
} from './actions';

@RegisterAction
Expand Down Expand Up @@ -44,11 +46,17 @@ class CommandEscInsertMode extends BaseCommand {
}
}
vimState.currentMode = ModeName.Normal;

// 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];
if (vimState.recordedState.count > 1 &&
(typeOfInsert instanceof CommandInsertAtCursor || typeOfInsert instanceof CommandInsertAfterCursor)) {
const isTypeToRepeatInsert = typeOfInsert instanceof CommandInsertAtCursor ||
typeOfInsert instanceof CommandInsertAfterCursor ||
typeOfInsert instanceof CommandInsertAtLineEnd ||
typeOfInsert instanceof CommandInsertAtFirstCharacter;

// If this is the type to repeat insert, do this now
if (vimState.recordedState.count > 1 && isTypeToRepeatInsert) {
const changeAction = vimState.recordedState.actionsRun[vimState.recordedState.actionsRun.length - 2] as DocumentContentChangeAction;
const changesArray = changeAction.contentChanges;
let docChanges: vscode.TextDocumentContentChangeEvent[] = [];
Expand Down
14 changes: 14 additions & 0 deletions test/mode/modeInsert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,20 @@ suite("Mode Insert", () => {
end: ['test==|=']
});

newTest({
title: "Can perform insert at start of line command prefixed with count",
start: ['tes|t'],
keysPressed: '2I_<Esc>',
end: ['_|_test']
});

newTest({
title: "Can perform append to end of line command prefixed with count",
start: ['t|est'],
keysPressed: '3A=<Esc>',
end: ['test==|=']
});

newTest({
title: "Can perform change char (s) command prefixed with count",
start: ['tes|ttest'],
Expand Down

0 comments on commit beead66

Please sign in to comment.