From 7ac3c436cae2fcc37841b9a6951c588d6b094a54 Mon Sep 17 00:00:00 2001 From: Feras Aldahlawi Date: Sun, 19 May 2019 00:08:16 -0700 Subject: [PATCH] Fix MoveHalfPageUp () when first line is visible. (#3776) * fix MoveHalfPageUp when first line is visible * fix when first line is visible --- src/actions/commands/actions.ts | 7 +++---- test/mode/modeNormal.test.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 4e8da5b51ce..eab38cd7042 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -734,13 +734,12 @@ class CommandMoveHalfPageUp extends CommandEditorScroll { const smoothScrolling = vscode.workspace.getConfiguration('editor').smoothScrolling; let lineOffset = 0; let editor = vscode.window.activeTextEditor!; - let startColumn = vimState.cursorStartPosition.character; let firstLine = editor.visibleRanges[0].start.line; let currentSelectionLine = vimState.cursorStopPosition.line; - lineOffset = currentSelectionLine - firstLine; - let timesToRepeat = vimState.recordedState.count || 1; + lineOffset = firstLine === 0 ? 0 : (currentSelectionLine - firstLine); + await vscode.commands.executeCommand('editorScroll', { to: this.to, by: this.by, @@ -757,7 +756,7 @@ class CommandMoveHalfPageUp extends CommandEditorScroll { newPosition = new Position(editor.selection.active.line, editor.selection.active.character); } else { let newFirstLine = editor.visibleRanges[0].start.line; - newPosition = new Position(newFirstLine + lineOffset, startColumn); + newPosition = new Position(newFirstLine + lineOffset, 0); } vimState.cursorStopPosition = newPosition; return vimState; diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index ef7894127ce..ed8884ad222 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -2310,4 +2310,25 @@ suite('Mode Normal', () => { endMode: ModeName.Insert, }); }); + + newTest({ + title: 'can handle when first line is visible and starting column is at the beginning', + start: ['hello world', 'hello', 'hi hello', '|foo'], + keysPressed: '', + end: ['|hello world', 'hello', 'hi hello', 'foo'], + }); + + newTest({ + title: 'can handle when first line is visible and starting column is at the end', + start: ['hello world', 'hello', 'hi hello', 'very long line at the bottom|'], + keysPressed: '', + end: ['|hello world', 'hello', 'hi hello', 'very long line at the bottom'], + }); + + newTest({ + title: 'can handle when first line is visible and starting column is in the middle', + start: ['hello world', 'hello', 'hi hello', 'very long line |at the bottom'], + keysPressed: '', + end: ['|hello world', 'hello', 'hi hello', 'very long line at the bottom'], + }); });