Skip to content

Commit

Permalink
Don't assume vimState.editor.visibleRanges is non-empty
Browse files Browse the repository at this point in the history
Fixes #7027
  • Loading branch information
J-Fields committed Aug 31, 2021
1 parent 06ca186 commit 2bdf6c8
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,15 @@ abstract class CommandEditorScroll extends BaseCommand {

public override async exec(position: Position, vimState: VimState): Promise<void> {
const timesToRepeat = vimState.recordedState.count || 1;
const visibleRange = vimState.editor.visibleRanges[0];
const scrolloff = configuration
.getConfiguration('editor')
.get<number>('cursorSurroundingLines', 0);

const visibleRange = vimState.editor.visibleRanges[0];
if (visibleRange === undefined) {
return;
}

const linesAboveCursor =
visibleRange.end.line - vimState.cursorStopPosition.line - timesToRepeat;
const linesBelowCursor =
Expand Down Expand Up @@ -530,14 +534,17 @@ abstract class CommandScrollAndMoveCursor extends BaseCommand {
/**
* @returns the number of lines this command should move the cursor
*/
protected abstract getNumLines(vimState: VimState): number;
protected abstract getNumLines(visibleRanges: vscode.Range[]): number;

public override async exec(position: Position, vimState: VimState): Promise<void> {
const { visibleRanges } = vimState.editor;
if (visibleRanges.length === 0) {
return;
}
const smoothScrolling = configuration
.getConfiguration('editor')
.get<boolean>('smoothScrolling', false);
const moveLines = (vimState.actionCount || 1) * this.getNumLines(vimState);
const moveLines = (vimState.actionCount || 1) * this.getNumLines(visibleRanges);

let scrollLines = moveLines;
if (this.to === 'down') {
Expand Down Expand Up @@ -583,9 +590,8 @@ class CommandMoveFullPageUp extends CommandScrollAndMoveCursor {
keys = ['<C-b>'];
to: EditorScrollDirection = 'up';

protected getNumLines(vimState: VimState) {
const visible = vimState.editor.visibleRanges[0];
return visible.end.line - visible.start.line;
protected getNumLines(visibleRanges: vscode.Range[]) {
return visibleRanges[0].end.line - visibleRanges[0].start.line;
}
}

Expand All @@ -594,9 +600,8 @@ class CommandMoveFullPageDown extends CommandScrollAndMoveCursor {
keys = ['<C-f>'];
to: EditorScrollDirection = 'down';

protected getNumLines(vimState: VimState) {
const visible = vimState.editor.visibleRanges[0];
return visible.end.line - visible.start.line;
protected getNumLines(visibleRanges: vscode.Range[]) {
return visibleRanges[0].end.line - visibleRanges[0].start.line;
}
}

Expand All @@ -605,8 +610,8 @@ class CommandMoveHalfPageDown extends CommandScrollAndMoveCursor {
keys = ['<C-d>'];
to: EditorScrollDirection = 'down';

protected getNumLines(vimState: VimState) {
return configuration.getScrollLines(vimState.editor.visibleRanges);
protected getNumLines(visibleRanges: vscode.Range[]) {
return configuration.getScrollLines(visibleRanges);
}
}

Expand All @@ -615,8 +620,8 @@ class CommandMoveHalfPageUp extends CommandScrollAndMoveCursor {
keys = ['<C-u>'];
to: EditorScrollDirection = 'up';

protected getNumLines(vimState: VimState) {
return configuration.getScrollLines(vimState.editor.visibleRanges);
protected getNumLines(visibleRanges: vscode.Range[]) {
return configuration.getScrollLines(visibleRanges);
}
}

Expand Down

0 comments on commit 2bdf6c8

Please sign in to comment.