From 08e6126c201cf9585e0f30a81eb70755c1d2db6c Mon Sep 17 00:00:00 2001 From: Jacques Kvam Date: Mon, 9 Apr 2018 12:07:02 -0700 Subject: [PATCH 1/2] commit work on starting settings --- schema/plugin.json | 53 ++++++++++++++++++++++++++++++++++++++++++++++ src/index.ts | 16 ++++++++------ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 schema/plugin.json diff --git a/schema/plugin.json b/schema/plugin.json new file mode 100644 index 0000000..1f7ba05 --- /dev/null +++ b/schema/plugin.json @@ -0,0 +1,53 @@ +{ + "jupyter.lab.setting-icon-class": "jp-NotebookIcon", + "jupyter.lab.setting-icon-label": "Notebook", + "title": "Vim Notebook Cell", + "description": "Vim Notebook Cell Settings", + "definitions": { + "editorConfig": { + "properties": { + "autoClosingBrackets": { + "type": "boolean" + }, + "lineNumbers": { + "type": "boolean" + }, + "lineWrap": { + "type": "boolean" + }, + "matchBrackets": { + "type": "boolean" + }, + "readOnly": { + "type": "boolean" + }, + "insertSpaces": { + "type": "boolean" + }, + "tabSize": { + "type": "number" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "properties": { + "editorConfig": { + "title": "Editor Configuration", + "description": "The configuration for all text editors.", + "$ref": "#/definitions/editorConfig", + "default": { + "autoClosingBrackets": true, + "lineNumbers": true, + "lineWrap": true, + "matchBrackets": true, + "readOnly": false, + "insertSpaces": true, + "tabSize": 4 + } + } + }, + "additionalProperties": false, + "type": "object" +} diff --git a/src/index.ts b/src/index.ts index 9b75914..7816d19 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'; @@ -38,7 +42,7 @@ const extension: JupyterLabPlugin = { id: 'jupyterlab_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,11 @@ class VimCell { private _app: JupyterLab; } -function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise { +function activateCellVim(app: JupyterLab, tracker: INotebookTracker, settingRegistry: ISettingRegistry): Promise { + const id = plugin.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]) => { function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null { const widget = tracker.currentWidget; const activate = args['activate'] !== false; From e009450082a152b49790dd73f4129bb4b9bfec25 Mon Sep 17 00:00:00 2001 From: Jacques Kvam Date: Sun, 26 Aug 2018 08:54:58 -0700 Subject: [PATCH 2/2] update --- package-lock.json | 33 ++++++++++++++++++++++++++++- package.json | 9 +++++--- schema/plugin.json | 53 ---------------------------------------------- schema/vim.json | 14 ++++++++++++ src/index.ts | 9 ++++++-- 5 files changed, 59 insertions(+), 59 deletions(-) delete mode 100644 schema/plugin.json create mode 100644 schema/vim.json 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/plugin.json b/schema/plugin.json deleted file mode 100644 index 1f7ba05..0000000 --- a/schema/plugin.json +++ /dev/null @@ -1,53 +0,0 @@ -{ - "jupyter.lab.setting-icon-class": "jp-NotebookIcon", - "jupyter.lab.setting-icon-label": "Notebook", - "title": "Vim Notebook Cell", - "description": "Vim Notebook Cell Settings", - "definitions": { - "editorConfig": { - "properties": { - "autoClosingBrackets": { - "type": "boolean" - }, - "lineNumbers": { - "type": "boolean" - }, - "lineWrap": { - "type": "boolean" - }, - "matchBrackets": { - "type": "boolean" - }, - "readOnly": { - "type": "boolean" - }, - "insertSpaces": { - "type": "boolean" - }, - "tabSize": { - "type": "number" - } - }, - "additionalProperties": false, - "type": "object" - } - }, - "properties": { - "editorConfig": { - "title": "Editor Configuration", - "description": "The configuration for all text editors.", - "$ref": "#/definitions/editorConfig", - "default": { - "autoClosingBrackets": true, - "lineNumbers": true, - "lineWrap": true, - "matchBrackets": true, - "readOnly": false, - "insertSpaces": true, - "tabSize": 4 - } - } - }, - "additionalProperties": false, - "type": "object" -} 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 7816d19..265629d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,7 +39,7 @@ 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, ISettingRegistry] @@ -190,10 +190,15 @@ class VimCell { } function activateCellVim(app: JupyterLab, tracker: INotebookTracker, settingRegistry: ISettingRegistry): Promise { - const id = plugin.id; + const id = extension.id; 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;