From 2571b7dab76336102868bb353c462df2013e22ec Mon Sep 17 00:00:00 2001 From: rebornix Date: Tue, 12 Jul 2016 14:16:51 +0800 Subject: [PATCH] Ctrl+U and Ctrl+D --- ROADMAP.md | 4 ++-- extension.ts | 2 +- package.json | 16 +++++++++++++++- src/actions/actions.ts | 20 ++++++++++++++++++++ src/mode/modeHandler.ts | 2 ++ 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 94bc3d86b44..0b39e0481b6 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -367,10 +367,10 @@ Status | Command | Description Status | Command | Description ---|--------|------------------------------ :x: | :1234: CTRL-E | window N lines downwards (default: 1) - :x: | :1234: CTRL-D | window N lines Downwards (default: 1/2 window) +:warning: | :1234: CTRL-D | window N lines Downwards (default: 1/2 window) :x: | :1234: CTRL-F | window N pages Forwards (downwards) :x: | :1234: CTRL-Y | window N lines upwards (default: 1) - :x: | :1234: CTRL-U | window N lines Upwards (default: 1/2 window) +:warning: | :1234: CTRL-U | window N lines Upwards (default: 1/2 window) :x: | :1234: CTRL-B | window N pages Backwards (upwards) :x: | z CR or zt | redraw, current line at top of window :warning: | z. or zz | redraw, current line at center of window diff --git a/extension.ts b/extension.ts index c2b1e36ae6b..04ac8a6da51 100644 --- a/extension.ts +++ b/extension.ts @@ -78,7 +78,7 @@ export function activate(context: vscode.ExtensionContext) { showCmdLine("", modeHandlerToFilename[activeFileName()]); }); - 'rfb'.split('').forEach(key => { + 'rfbdu'.split('').forEach(key => { registerCommand(context, `extension.vim_ctrl+${key}`, () => handleKeyEvent(`ctrl+${key}`)); }); diff --git a/package.json b/package.json index 3ddd250ebce..06f54c4ebd8 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,16 @@ "command": "extension.vim_ctrl+b", "when": "editorTextFocus" }, + { + "key": "ctrl+u", + "command": "extension.vim_ctrl+u", + "when": "editorTextFocus" + }, + { + "key": "ctrl+d", + "command": "extension.vim_ctrl+d", + "when": "editorTextFocus" + }, { "key": "ctrl+w", "command": "extension.vim_switchWindow", @@ -109,7 +119,7 @@ "vim.insertModeKeyBindings": { "type": "array", "description": "Keybinding overrides to use for insert mode." - }, + }, "vim.useSolidBlockCursor": { "type": "boolean", "description": "Use a non blinking block cursor." @@ -117,6 +127,10 @@ "vim.visualModeKeyBindings": { "type": "object", "description": "Keybinding overrides to use for visual mode." + }, + "vim.scroll": { + "type": "number", + "description": "Number of lines to scroll with CTRL-U and CTRL-D commands." } } } diff --git a/src/actions/actions.ts b/src/actions/actions.ts index cb39ead1b85..91bcca137a6 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -1013,6 +1013,26 @@ class CommandMoveFullPageUp extends BaseCommand { } } +@RegisterAction +class MCommandMoveHalfPageDown extends BaseMovement { + modes = [ModeName.Normal]; + keys = ["ctrl+d"]; + + public async execAction(position: Position, vimState: VimState): Promise { + return new Position(Math.min(TextEditor.getLineCount() - 1, position.line + vimState.settings.scroll), position.character); + } +} + +@RegisterAction +class MCommandMoveHalfPageUp extends BaseMovement { + modes = [ModeName.Normal]; + keys = ["ctrl+u"]; + + public async execAction(position: Position, vimState: VimState): Promise { + return new Position(Math.max(0, position.line - vimState.settings.scroll), position.character); + } +} + @RegisterAction class CommandDeleteToLineEnd extends BaseCommand { modes = [ModeName.Normal]; diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index f1646d06f2d..812aaceaed7 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -125,6 +125,7 @@ export class VimState { export class VimSettings { useSolidBlockCursor = false; + scroll = 20; } export class SearchState { @@ -477,6 +478,7 @@ export class ModeHandler implements vscode.Disposable { private loadSettings(): void { this._vimState.settings.useSolidBlockCursor = vscode.workspace.getConfiguration("vim") .get("useSolidBlockCursor", false); + this._vimState.settings.scroll = vscode.workspace.getConfiguration("vim").get("scroll", 20) || 20; } /**