Skip to content

Commit

Permalink
Fix MoveHalfPageUp (<C-u>) when first line is visible. (VSCodeVim#3776)
Browse files Browse the repository at this point in the history
* fix MoveHalfPageUp when first line is visible

* fix <C-u> when first line is visible
  • Loading branch information
alzabone authored and jpoon committed May 19, 2019
1 parent 7857681 commit 7ac3c43
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2310,4 +2310,25 @@ suite('Mode Normal', () => {
endMode: ModeName.Insert,
});
});

newTest({
title: 'can handle <C-u> when first line is visible and starting column is at the beginning',
start: ['hello world', 'hello', 'hi hello', '|foo'],
keysPressed: '<C-u>',
end: ['|hello world', 'hello', 'hi hello', 'foo'],
});

newTest({
title: 'can handle <C-u> 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: '<C-u>',
end: ['|hello world', 'hello', 'hi hello', 'very long line at the bottom'],
});

newTest({
title: 'can handle <C-u> 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: '<C-u>',
end: ['|hello world', 'hello', 'hi hello', 'very long line at the bottom'],
});
});

0 comments on commit 7ac3c43

Please sign in to comment.