Skip to content

Commit

Permalink
Merge pull request #1837 from xconverge/fix-yiw-cursor-pos
Browse files Browse the repository at this point in the history
Fix yiw cursor pos
  • Loading branch information
xconverge authored Jun 14, 2017
2 parents 877d30f + 9bd0023 commit 99b7650
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/actions/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Range } from './../common/motion/range';
import { ModeName } from './../mode/mode';
import { TextEditor } from './../textEditor';
import { Configuration } from './../configuration/configuration';
import { TextObjectMovement } from './textobject';
import {
BaseAction, RegisterAction, compareKeypressSequence
} from './base';
Expand Down Expand Up @@ -233,7 +234,15 @@ export class YankOperator extends BaseOperator {
vimState.currentMode = ModeName.Normal;
vimState.cursorStartPosition = start;

if (originalMode === ModeName.Normal) {
// Only change cursor position if we ran a text object movement
let moveCursor = false;
if (vimState.recordedState.actionsRun.length > 1) {
if (vimState.recordedState.actionsRun[1] instanceof TextObjectMovement) {
moveCursor = true;
}
}

if (originalMode === ModeName.Normal && !moveCursor) {
vimState.allCursors = vimState.cursorPositionJustBeforeAnythingHappened.map(x => new Range(x, x));
} else {
vimState.cursorPosition = start;
Expand Down
8 changes: 8 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ suite("Mode Normal", () => {
endMode: ModeName.Insert
});

newTest({
title: "Can handle 'yiw' with correct cursor ending position",
start: ['tes|t'],
keysPressed: 'yiwp',
end: ['ttes|test'],
endMode: ModeName.Normal
});

newTest({
title: "Can handle 'ciw'",
start: ['text text tex|t'],
Expand Down

0 comments on commit 99b7650

Please sign in to comment.