Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings to enable double duty Esc and to disable Shift-Esc override in Command mode #110

Merged
merged 5 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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": ""
},
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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}`;
Expand All @@ -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}`;
Expand Down