Skip to content

Commit

Permalink
Implement stickyCursor
Browse files Browse the repository at this point in the history
This setting emulates vim's limitation (or feature, depending on how you look at it) which kept the cursor within the viewport, even when scrolling with the mouse.
Fixes #873, #3846
  • Loading branch information
J-Fields committed Sep 28, 2019
1 parent 72554fa commit 7070367
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
20 changes: 20 additions & 0 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,26 @@ export async function activate(context: vscode.ExtensionContext) {
true
);

registerEventListener(context, vscode.window.onDidChangeTextEditorVisibleRanges, async event => {
if (configuration.stickyCursor) {
taskQueue.enqueueTask(async () => {
const viewPort = event.visibleRanges[0];
const mh = await getAndUpdateModeHandler();
if (viewPort.start.line > mh.vimState.cursorStopPosition.line) {
await vscode.commands.executeCommand('cursorMove', {
to: 'viewPortTop',
});
mh.syncCursors();
} else if (mh.vimState.cursorStopPosition.line > viewPort.end.line) {
await vscode.commands.executeCommand('cursorMove', {
to: 'viewPortBottom',
});
mh.syncCursors();
}
});
}
});

const compositionState = new CompositionState();

// override vscode commands
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,11 @@
"type": "boolean",
"description": "Searches wrap around the end of the file.",
"default": true
},
"vim.stickyCursor": {
"type": "boolean",
"description": "If true, the cursor will always be kept within the viewport.",
"default": false
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class Configuration implements IConfiguration {
sneakUseIgnorecaseAndSmartcase = false;
sneakReplacesF = false;

stickyCursor = false;

surround = true;

easymotion = false;
Expand Down

0 comments on commit 7070367

Please sign in to comment.