From 4aa1c55298ab1e0b86e2a66145620c1f363519a4 Mon Sep 17 00:00:00 2001 From: rebornix Date: Tue, 12 Jul 2016 10:25:36 +0800 Subject: [PATCH] Fix#369. `dw` eats EOF. --- src/actions/actions.ts | 4 ++-- src/motion/position.ts | 4 ++++ test/mode/modeNormal.test.ts | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index cb39ead1b85..e365a535658 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -1512,8 +1512,8 @@ export class MoveWordBegin extends BaseMovement { next line. */ - if (result.isLineBeginning()) { - return result.getLeftThroughLineBreaks(); + if (result.line > position.line + 1 || (result.line === position.line + 1 && result.isFirstWordOfLine())) { + return position.getLineEnd(); } if (result.isLineEnd()) { diff --git a/src/motion/position.ts b/src/motion/position.ts index f7a9f6ba276..7ebf65c40ee 100644 --- a/src/motion/position.ts +++ b/src/motion/position.ts @@ -369,6 +369,10 @@ export class Position extends vscode.Position { return this.character >= Position.getLineLength(this.line); } + public isFirstWordOfLine(): boolean { + return Position.getFirstNonBlankCharAtLine(this.line) === this.character; + } + public isAtDocumentEnd(): boolean { return this.line === TextEditor.getLineCount() - 1 && this.isLineEnd(); } diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index f414eb64757..82bd7d21573 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -63,6 +63,20 @@ suite("Mode Normal", () => { end: ["one| "], }); + newTest({ + title: "Can handle dw across lines", + start: ['one |two', ' three'], + keysPressed: 'dw', + end: ["one| ", " three"] + }); + + newTest({ + title: "Can handle dw across lines", + start: ['one |two', '', 'three'], + keysPressed: 'dw', + end: ["one| ", "", "three"] + }); + newTest({ title: "Can handle dd last line", start: ['one', '|two'],