diff --git a/schema/plugin.json b/schema/plugin.json index 3a5083c..5db429b 100644 --- a/schema/plugin.json +++ b/schema/plugin.json @@ -96,15 +96,25 @@ "command": "vim:select-above-execute-markdown" }, { - "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode", + "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'][data-jp-vim-esc-to-cmd-mode='false'] .jp-Notebook.jp-mod-editMode", "keys": ["Escape"], "command": "vim:leave-insert-mode" }, { - "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook.jp-mod-editMode", + "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'][data-jp-vim-esc-to-cmd-mode='true'] .jp-Notebook.jp-mod-editMode", + "keys": ["Escape"], + "command": "vim:leave-current-mode" + }, + { + "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'][data-jp-vim-esc-to-cmd-mode='false'] .jp-Notebook.jp-mod-editMode", "keys": ["Ctrl ["], "command": "vim:leave-insert-mode" }, + { + "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'][data-jp-vim-esc-to-cmd-mode='true'] .jp-Notebook.jp-mod-editMode", + "keys": ["Ctrl ["], + "command": "vim:leave-current-mode" + }, { "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'] .jp-Notebook:focus", "keys": ["Ctrl I"], @@ -126,7 +136,7 @@ "command": "notebook:enter-command-mode" }, { - "selector": ".jp-Notebook.jp-mod-commandMode", + "selector": ".jp-NotebookPanel[data-jp-vim-mode='true'][data-jp-vim-shift-esc-override-browser='true'] .jp-Notebook.jp-mod-commandMode", "keys": ["Shift Escape"], "command": "" }, @@ -285,6 +295,22 @@ "description": "Enable/disable vim in text editors (may require a page refresh)", "default": true }, + "cmdModeKeys": { + "type": "object", + "title": "Notebook shortcut key bindings for switching from vim Normal mode to Jupyter Command mode", + "properties": { + "escToCmdMode": { + "type": "boolean", + "title": "Enable `Esc` and `Ctrl-[` leaving vim Normal mode to Jupyter Command mode", + "default": true + }, + "shiftEscOverrideBrowser": { + "type": "boolean", + "title": "Override `Shift-Esc` browser shortcut in Jupyter Command mode", + "default": true + } + } + }, "extraKeybindings": { "type": "array", "title": "Extra Vim Keybindings", diff --git a/src/index.ts b/src/index.ts index 2e74f48..048797c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,11 +23,14 @@ import { IKeybinding } from './codemirrorCommands'; import { addNotebookCommands } from './labCommands'; +import { PartialJSONObject } from '@lumino/coreutils'; const PLUGIN_NAME = '@axlair/jupyterlab_vim'; const TOGGLE_ID = 'jupyterlab-vim:toggle'; let enabled = false; let enabledInEditors = true; +let escToCmdMode = true; +let shiftEscOverrideBrowser = true; /** * Initialization data for the jupyterlab_vim extension. @@ -170,6 +173,18 @@ async function activateCellVim( enabled = settings.get('enabled').composite === true; enabledInEditors = settings.get('enabledInEditors').composite === true; + + const cmdModeKeys = settings.get('cmdModeKeys') + .composite as PartialJSONObject; + if (!cmdModeKeys) { + // no-op + } else { + escToCmdMode = cmdModeKeys['escToCmdMode'] as boolean; + shiftEscOverrideBrowser = cmdModeKeys[ + 'shiftEscOverrideBrowser' + ] as boolean; + } + app.commands.notifyCommandChanged(TOGGLE_ID); cellManager.enabled = enabled; @@ -194,6 +209,8 @@ async function activateCellVim( notebookTracker.forEach(notebook => { notebook.node.dataset.jpVimMode = `${enabled}`; + notebook.node.dataset.jpVimEscToCmdMode = `${escToCmdMode}`; + notebook.node.dataset.jpVimShiftEscOverrideBrowser = `${shiftEscOverrideBrowser}`; }); editorTracker.forEach(document => { document.node.dataset.jpVimMode = `${enabled && enabledInEditors}`; @@ -204,6 +221,8 @@ async function activateCellVim( // make sure our css selector is added to new notebooks notebookTracker.widgetAdded.connect((sender, notebook) => { notebook.node.dataset.jpVimMode = `${enabled}`; + notebook.node.dataset.jpVimEscToCmdMode = `${escToCmdMode}`; + notebook.node.dataset.jpVimShiftEscOverrideBrowser = `${shiftEscOverrideBrowser}`; }); editorTracker.widgetAdded.connect((sender, document) => { document.node.dataset.jpVimMode = `${enabled && enabledInEditors}`;