Skip to content

Commit

Permalink
Merge pull request mauricedb#12 from mauricedb/fix-reveal-range
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricedb authored Oct 19, 2020
2 parents 7ac80e4 + edef925 commit 2eb9c03
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/instruction-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { commands, Position, Selection, Uri, window, workspace } from 'vscode';
import {
commands,
Position,
Selection,
TextEditorRevealType,
Uri,
window,
workspace,
} from 'vscode';
import { join, dirname } from 'path';

import {
Expand Down Expand Up @@ -66,10 +74,8 @@ const typeTextIntoActiveTextEditor = async (
editBuilder.insert(editor.selection.active, char!);
if (char === '\n') {
pos = new Position(pos.line + 1, pos.character);
// scroll to last line
const lastLine = editor.document.lineCount - 1;
const lastLineRange = editor.document.lineAt(lastLine).range;
editor.revealRange(lastLineRange);
// scroll to current line if needed
editor.revealRange(editor.selection, TextEditorRevealType.Default);
} else {
pos = new Position(pos.line, pos.character + 1);
}
Expand Down Expand Up @@ -124,7 +130,11 @@ export const goto = async (instruction: GoTo): Promise<void> => {

const position = new Position(line - 1, column - 1);
editor.selection = new Selection(position, position);
editor.revealRange(editor.selection);
editor.revealRange(
editor.selection,
TextEditorRevealType.InCenterIfOutsideViewport
);

await timeout(getDelay());
};

Expand Down

0 comments on commit 2eb9c03

Please sign in to comment.