initial implementation of allowing user to selectively disable some key combinations with a config option

This commit is contained in:
xconverge 2017-03-24 20:46:56 -07:00
parent b34e72f2a9
commit e2667d5b7d
3 changed files with 59 additions and 26 deletions

View File

@ -15,7 +15,7 @@ import { Position } from './src/motion/position';
import { Globals } from './src/globals';
import { AngleBracketNotation } from './src/notation';
import { ModeName } from './src/mode/mode';
import { Configuration } from './src/configuration/configuration'
import { Configuration, IHandleKeys } from './src/configuration/configuration'
interface VSCodeKeybinding {
key: string;
@ -245,6 +245,11 @@ export async function activate(context: vscode.ExtensionContext) {
showCmdLine("", modeHandlerToEditorIdentity[new EditorIdentity(vscode.window.activeTextEditor).toString()]);
});
// Get configuration setting for handled keys, this allows user to disable
// certain key comboinations
const handleKeys = vscode.workspace.getConfiguration('vim')
.get<IHandleKeys[]>("handleKeys", []);
for (let keybinding of packagejson.contributes.keybindings) {
let keyToBeBound = "";
@ -261,6 +266,26 @@ export async function activate(context: vscode.ExtensionContext) {
let bracketedKey = AngleBracketNotation.Normalize(keyToBeBound);
// Set context for key that is not used
// This either happens when user sets useCtrlKeys to false (ctrl keys are not used then)
// Or if user usese vim.handleKeys configuration option to set certain combinations to false
// By default, all key combinations are used so start with true
let useKey = true;
//Check for configuration setting disabling combo
if (handleKeys[bracketedKey] !== undefined) {
if (handleKeys[bracketedKey] === false) {
useKey = false;
}
} else if (!Configuration.useCtrlKeys && (bracketedKey.slice(1, 3) === "C-")) {
// Check for useCtrlKeys and if it is a <C- ctrl based keybinding
useKey = false;
}
// Set the context of whether or not this key will be used based on criteria from above
vscode.commands.executeCommand('setContext', 'vim.use' + bracketedKey, useKey);
// Register the keybinding
registerCommand(context, keybinding.command, () => handleKeyEvent(`${ bracketedKey }`));
}

View File

@ -70,17 +70,17 @@
{
"key": "cmd+d",
"command": "extension.vim_cmd+d",
"when": "editorTextFocus && !inDebugRepl"
"when": "editorTextFocus && vim.use<D-d> !inDebugRepl"
},
{
"key": "cmd+a",
"command": "extension.vim_cmd+a",
"when": "editorTextFocus && !inDebugRepl && vim.mode != 'Insert'"
"when": "editorTextFocus && vim.use<D-a> !inDebugRepl && vim.mode != 'Insert'"
},
{
"key": "ctrl+d",
"command": "extension.vim_ctrl+d",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-d> && !inDebugRepl"
},
{
"key": "ctrl+alt+down",
@ -119,107 +119,107 @@
{
"key": "ctrl+r",
"command": "extension.vim_ctrl+r",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-r> && !inDebugRepl"
},
{
"key": "ctrl+f",
"command": "extension.vim_ctrl+f",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-f> && !inDebugRepl"
},
{
"key": "ctrl+b",
"command": "extension.vim_ctrl+b",
"when": "editorTextFocus && vim.useCtrlKeys && vim.mode != 'Insert' && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-b> && vim.mode != 'Insert' && !inDebugRepl"
},
{
"key": "ctrl+j",
"command": "extension.vim_ctrl+j",
"when": "editorTextFocus && vim.useCtrlKeys && vim.mode != 'Insert' && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-j> && vim.mode != 'Insert' && !inDebugRepl"
},
{
"key": "ctrl+k",
"command": "extension.vim_ctrl+k",
"when": "editorTextFocus && vim.useCtrlKeys && vim.mode != 'Insert' && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-k> && vim.mode != 'Insert' && !inDebugRepl"
},
{
"key": "ctrl+h",
"command": "extension.vim_ctrl+h",
"when": "editorTextFocus && vim.useCtrlKeys && vim.mode == 'Insert' && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-h> && vim.mode == 'Insert' && !inDebugRepl"
},
{
"key": "ctrl+e",
"command": "extension.vim_ctrl+e",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-e> && !inDebugRepl"
},
{
"key": "ctrl+y",
"command": "extension.vim_ctrl+y",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-y> && !inDebugRepl"
},
{
"key": "ctrl+u",
"command": "extension.vim_ctrl+u",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-u> && !inDebugRepl"
},
{
"key": "ctrl+o",
"command": "extension.vim_ctrl+o",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-o> && !inDebugRepl"
},
{
"key": "ctrl+i",
"command": "extension.vim_ctrl+i",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-i> && !inDebugRepl"
},
{
"key": "ctrl+v",
"command": "extension.vim_ctrl+v",
"when": "editorTextFocus && vim.mode != 'Insert' && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-v> && vim.mode != 'Insert' && !inDebugRepl"
},
{
"key": "cmd+v",
"command": "extension.vim_cmd+v",
"when": "editorTextFocus && vim.mode == 'SearchInProgressMode' && !inDebugRepl"
"when": "editorTextFocus && vim.use<D-v> && vim.mode == 'SearchInProgressMode' && !inDebugRepl"
},
{
"key": "ctrl+[",
"command": "extension.vim_ctrl+[",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-[> !inDebugRepl"
},
{
"key": "ctrl+w",
"command": "extension.vim_ctrl+w",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-w> !inDebugRepl"
},
{
"key": "ctrl+c",
"command": "extension.vim_ctrl+c",
"when": "editorTextFocus && !inDebugRepl && vim.overrideCtrlC"
"when": "editorTextFocus && vim.use<C-c> !inDebugRepl && vim.overrideCtrlC"
},
{
"key": "cmd+c",
"command": "extension.vim_cmd+c",
"when": "editorTextFocus && vim.overrideCopy && !inDebugRepl"
"when": "editorTextFocus && vim.use<D-c> vim.overrideCopy && !inDebugRepl"
},
{
"key": "ctrl+a",
"command": "extension.vim_ctrl+a",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-a> !inDebugRepl"
},
{
"key": "ctrl+n",
"command": "extension.vim_ctrl+n",
"when": "suggestWidgetVisible && vim.useCtrlKeys"
"when": "suggestWidgetVisible && vim.use<C-n> vim.useCtrlKeys"
},
{
"key": "ctrl+p",
"command": "extension.vim_ctrl+p",
"when": "suggestWidgetVisible && vim.useCtrlKeys"
"when": "suggestWidgetVisible && vim.use<C-p> vim.useCtrlKeys"
},
{
"key": "ctrl+x",
"command": "extension.vim_ctrl+x",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-x> !inDebugRepl"
},
{
"key": "ctrl+shift+2",
@ -229,7 +229,7 @@
{
"key": "ctrl+t",
"command": "extension.vim_ctrl+t",
"when": "editorTextFocus && vim.useCtrlKeys && !inDebugRepl"
"when": "editorTextFocus && vim.use<C-t> !inDebugRepl"
},
{
"key": "ctrl+pagedown",
@ -380,6 +380,10 @@
"vim.startInInsertMode": {
"type": "boolean",
"description": "Start in Insert Mode."
},
"vim.handleKeys": {
"type": "array",
"description": "Allow to delegate certain key combinations back to VSCode"
}
}
}

View File

@ -10,6 +10,10 @@ export type ValueMapping = {
[key: string]: OptionValue
}
export interface IHandleKeys {
[key: string]: boolean;
}
/**
* Every Vim option we support should
* 1. Be added to contribution section of `package.json`.