diff --git a/package-lock.json b/package-lock.json index cc744c0..9294963 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jupyterlab_vim", - "version": "0.9.0", + "version": "0.9.1-dev", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -510,6 +510,23 @@ } } }, + "@jupyterlab/coreutils": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@jupyterlab/coreutils/-/coreutils-2.1.4.tgz", + "integrity": "sha512-jSjn+xZj+kJrSWJ2Hz3jpxq0EXNpQrsnf+dD+pnDPc8mAeQ2XVu/x63VZyIDx8u2MELrIodFsUmQTxeudXKlOg==", + "requires": { + "@phosphor/algorithm": "^1.1.2", + "@phosphor/coreutils": "^1.3.0", + "@phosphor/disposable": "^1.1.2", + "@phosphor/signaling": "^1.2.2", + "ajv": "~5.1.6", + "comment-json": "^1.1.3", + "minimist": "~1.2.0", + "moment": "~2.21.0", + "path-posix": "~1.0.0", + "url-parse": "~1.4.3" + } + }, "@jupyterlab/notebook": { "version": "0.18.3", "resolved": "https://registry.npmjs.org/@jupyterlab/notebook/-/notebook-0.18.3.tgz", @@ -1197,6 +1214,11 @@ "object-assign": "^4.1.1" } }, + "querystringify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.0.0.tgz", + "integrity": "sha512-eTPo5t/4bgaMNZxyjWx6N2a6AuE0mq51KWvpc7nU/MAqixcI6v6KrGUKES0HaomdnolQBBXU/++X6/QQ9KL4tw==" + }, "react": { "version": "16.4.1", "resolved": "https://registry.npmjs.org/react/-/react-16.4.1.tgz", @@ -1296,6 +1318,15 @@ "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.0.2.tgz", "integrity": "sha1-rOEWq1V80Zc4ak6I9GhTeMiy5Po=" }, + "url-parse": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.3.tgz", + "integrity": "sha512-rh+KuAW36YKo0vClhQzLLveoj8FwPJNu65xLb7Mrt+eZht0IPT0IXgSv8gcMegZ6NvjJUALf6Mf25POlMwD1Fw==", + "requires": { + "querystringify": "^2.0.0", + "requires-port": "^1.0.0" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/package.json b/package.json index 3f57318..112221b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab_vim", - "version": "0.9.0", + "version": "0.9.1-dev", "description": "Code cell vim bindings", "author": "Jacques Kvam", "main": "lib/index.js", @@ -28,16 +28,19 @@ }, "files": [ "lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}", - "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}" + "style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}", + "schema/*.json" ], "jupyterlab": { - "extension": true + "extension": true, + "schemaDir": "schema" }, "dependencies": { "@jupyterlab/application": "^0.18.0", "@jupyterlab/codemirror": "^0.18.0", "@jupyterlab/cells": "^0.18.0", "@jupyterlab/notebook": "^0.18.0", + "@jupyterlab/coreutils": "^2.1.0", "@phosphor/commands": "^1.4.0", "@phosphor/coreutils": "^1.3.0", "@phosphor/domutils": "^1.1.2", diff --git a/schema/vim.json b/schema/vim.json new file mode 100644 index 0000000..089a934 --- /dev/null +++ b/schema/vim.json @@ -0,0 +1,14 @@ +{ + "jupyter.lab.setting-icon-class": "jp-NotebookIcon", + "jupyter.lab.setting-icon-label": "Notebook", + "title": "Vim Notebook Cell", + "description": "Vim Notebook Cell Settings", + "properties": { + "enable": { + "type": "boolean", + "title": "Enable", + "default": true + } + }, + "type": "object" +} diff --git a/src/index.ts b/src/index.ts index 9b75914..265629d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,10 @@ import { MarkdownCell } from '@jupyterlab/cells'; +import { + ISettingRegistry +} from '@jupyterlab/coreutils'; + import { CodeMirrorEditor } from '@jupyterlab/codemirror'; @@ -35,10 +39,10 @@ const IS_MAC = !!navigator.platform.match(/Mac/i); * Initialization data for the jupyterlab_vim extension. */ const extension: JupyterLabPlugin = { - id: 'jupyterlab_vim', + id: 'jupyterlab_vim:vim', autoStart: true, activate: activateCellVim, - requires: [INotebookTracker] + requires: [INotebookTracker, ISettingRegistry] }; class VimCell { @@ -77,8 +81,7 @@ class VimCell { lvim.defineEx('quit', 'q', function(cm: any) { commands.execute('notebook:enter-command-mode'); }); - - (CodeMirror as any).Vim.handleKey(editor.editor, ''); + lvim.handleKey(editor.editor, ''); lvim.defineMotion('moveByLinesOrCell', (cm: any, head: any, motionArgs: any, vim: any) => { let cur = head; let endCh = cur.ch; @@ -186,10 +189,16 @@ class VimCell { private _app: JupyterLab; } -function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise { +function activateCellVim(app: JupyterLab, tracker: INotebookTracker, settingRegistry: ISettingRegistry): Promise { + const id = extension.id; + const { commands, shell } = app; - Promise.all([app.restored]).then(([args]) => { - const { commands, shell } = app; + Promise.all([settingRegistry.load(id), app.restored]).then(([settings, args]) => { + // Promise.all([app.restored]).then(([args]) => { + const enabled = settings.get('enable').composite as boolean; + if (enabled === false) { + return; + } function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null { const widget = tracker.currentWidget; const activate = args['activate'] !== false;