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'],