From c13a3a43bbffebbea5bbb83e2710c63cd5a03d9b Mon Sep 17 00:00:00 2001 From: Jason Fields Date: Sun, 29 Dec 2019 12:56:48 -0500 Subject: [PATCH] Center the viewport around the cursor if the previous action moved the cursor at least 15 lines off screen Fixes #2960 --- src/mode/modeHandler.ts | 13 +++++++++++-- src/state/vimState.ts | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 83eff3a13d1..78a45c5920e 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -1294,17 +1294,26 @@ export class ModeHandler implements vscode.Disposable { } } + const visibleRange = vimState.editor.visibleRanges[0]; + const centerViewportAroundCursor = + visibleRange.start.line - vimState.cursorStopPosition.line >= 15 || + vimState.cursorStopPosition.line - visibleRange.end.line >= 15; + const revealType = centerViewportAroundCursor + ? vscode.TextEditorRevealType.InCenter + : vscode.TextEditorRevealType.Default; + // Scroll to position of cursor if (this.vimState.currentMode === Mode.SearchInProgressMode) { const nextMatch = globalState.searchState!.getNextSearchMatchPosition( vimState.cursorStopPosition ).pos; - this.vimState.editor.revealRange(new vscode.Range(nextMatch, nextMatch)); + this.vimState.editor.revealRange(new vscode.Range(nextMatch, nextMatch), revealType); } else { if (args.revealRange) { this.vimState.editor.revealRange( - new vscode.Range(vimState.cursorStopPosition, vimState.cursorStopPosition) + new vscode.Range(vimState.cursorStopPosition, vimState.cursorStopPosition), + revealType ); } } diff --git a/src/state/vimState.ts b/src/state/vimState.ts index 2531c8f9c00..3a65d3bad05 100644 --- a/src/state/vimState.ts +++ b/src/state/vimState.ts @@ -13,7 +13,6 @@ import { Range } from './../common/motion/range'; import { RecordedState } from './recordedState'; import { RegisterMode } from './../register/register'; import { ReplaceState } from './../state/replaceState'; -import { globalState } from './../state/globalState'; /** * The VimState class holds permanent state that carries over from action