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 ability to disable plugin via settings #112

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lib/
node_modules/
*.egg-info/
.ipynb_checkpoints
.idea

# Created by https://www.gitignore.io/api/node

Expand Down Expand Up @@ -81,7 +82,7 @@ typings/
.LSOverride

# Icon must end with two \r
Icon
Icon

# Thumbnails
._*
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@
},
"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/*"
],
"jupyterlab": {
"extension": true
"extension": true,
"schemaDir": "schema"
},
"dependencies": {
"@jupyterlab/application": "^1.0.1",
"@jupyterlab/codemirror": "^1.0.1",
"@jupyterlab/cells": "^1.0.1",
"@jupyterlab/coreutils": "^3.2.0",
"@jupyterlab/notebook": "^1.0.1",
"@phosphor/commands": "^1.6.3",
"@phosphor/coreutils": "^1.3.1",
Expand Down
13 changes: 13 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "Notebook Vim",
"type": "object",
"additionalProperties": true,
"properties": {
"enabled": {
"type": "boolean",
"title": "Enabled",
"description": "Enable/disable notebook vim (may require a page refresh)",
"default": true
}
}
}
47 changes: 39 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
CodeMirrorEditor
} from '@jupyterlab/codemirror';
import { ISettingRegistry } from '@jupyterlab/coreutils';

import {
ReadonlyJSONObject
Expand All @@ -33,15 +34,17 @@ import 'codemirror/keymap/vim.js';
* A boolean indicating whether the platform is Mac.
*/
const IS_MAC = !!navigator.platform.match(/Mac/i);
const PLUGIN_NAME = 'jupyterlab_vim';
let enabled = false;

/**
* Initialization data for the jupyterlab_vim extension.
*/
const extension: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab_vim',
id: PLUGIN_NAME,
autoStart: true,
activate: activateCellVim,
requires: [INotebookTracker]
requires: [INotebookTracker, ISettingRegistry]
};

class VimCell {
Expand All @@ -54,6 +57,9 @@ class VimCell {
}

private _onActiveCellChanged(): void {
if(!enabled) {
return;
}
// if (this._prevActive && !this._prevActive.isDisposed) {
// this._prevActive.metadata.changed.disconnect(this._onMetadataChanged, this);
// }
Expand Down Expand Up @@ -189,9 +195,8 @@ class VimCell {
private _app: JupyterFrontEnd;
}

function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker): Promise<void> {

Promise.all([app.restored]).then(([args]) => {
async function setupPlugin(app: JupyterFrontEnd, tracker: INotebookTracker) {
await app.restored;
const { commands, shell } = app;
function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null {
const widget = tracker.currentWidget;
Expand All @@ -204,7 +209,7 @@ function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker): Promi
return widget;
}
function isEnabled(): boolean {
return tracker.currentWidget !== null &&
return enabled && tracker.currentWidget !== null &&
tracker.currentWidget === app.shell.currentWidget;
}

Expand Down Expand Up @@ -598,8 +603,34 @@ function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker): Promi
});

// tslint:disable:no-unused-expression
new VimCell(app, tracker);
});
return new VimCell(app, tracker);
}

function activateCellVim(app: JupyterFrontEnd, tracker: INotebookTracker, settingRegistry: ISettingRegistry): Promise<void> {
let hasEverBeenEnabled = false;

function updateSettings(settings: ISettingRegistry.ISettings) {
// TODO: This does not reset any cells that have been used with VIM
enabled = settings.get('enabled').composite === true;
if (enabled && !hasEverBeenEnabled) {
hasEverBeenEnabled = true;
setupPlugin(app, tracker);
}
}

settingRegistry.load(`${PLUGIN_NAME}:settings`).then(
(settings: ISettingRegistry.ISettings) => {
updateSettings(settings);
settings.changed.connect(updateSettings);
},
(err: Error) => {
console.error(
`Could not load settings, so did not active ${PLUGIN_NAME}: ${err}`
);
}
);



return Promise.resolve();
}
Expand Down
54 changes: 54 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@
path-posix "~1.0.0"
url-parse "~1.4.3"

"@jupyterlab/coreutils@^3.2.0":
version "3.2.0"
resolved "http://npmrepo/@jupyterlab%2fcoreutils/-/coreutils-3.2.0.tgz#dd4d887bdedfea4c8545d46d297531749cb13724"
integrity sha512-LATiUsHuwze/h3JC2EZOBV+kGBoUKO3npqw/Pcgge4bz09xF/oTDrx4G8jl5eew3w1dCUNp9eLduNh8Orrw7xQ==
dependencies:
"@phosphor/commands" "^1.7.0"
"@phosphor/coreutils" "^1.3.1"
"@phosphor/disposable" "^1.3.0"
"@phosphor/properties" "^1.1.3"
"@phosphor/signaling" "^1.3.0"
ajv "^6.5.5"
json5 "^2.1.0"
minimist "~1.2.0"
moment "^2.24.0"
path-posix "~1.0.0"
url-parse "~1.4.3"

"@jupyterlab/docregistry@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@jupyterlab/docregistry/-/docregistry-1.0.1.tgz#28ca14e7c43c161384d5582e011b0a70522bb8eb"
Expand Down Expand Up @@ -320,6 +337,11 @@
resolved "https://registry.yarnpkg.com/@phosphor/algorithm/-/algorithm-1.1.3.tgz#fb0e974f4e81aadc06f948770b3060c4ec8a1e27"
integrity sha512-+dkdYTBglR+qGnLVQdCvYojNZMGxf+xSl1Jeksha3pm7niQktSFz2aR5gEPu/nI5LM8T8slTpqE4Pjvq8P+IVA==

"@phosphor/algorithm@^1.2.0":
version "1.2.0"
resolved "http://npmrepo/@phosphor%2falgorithm/-/algorithm-1.2.0.tgz#4a19aa59261b7270be696672dc3f0663f7bef152"
integrity sha512-C9+dnjXyU2QAkWCW6QVDGExk4hhwxzAKf5/FIuYlHAI9X5vFv99PYm0EREDxX1PbMuvfFBZhPNu0PvuSDQ7sFA==

"@phosphor/application@^1.6.3":
version "1.6.4"
resolved "https://registry.yarnpkg.com/@phosphor/application/-/application-1.6.4.tgz#8e8d649260d700ac77fb1cfb78af566730052fd0"
Expand Down Expand Up @@ -348,6 +370,18 @@
"@phosphor/keyboard" "^1.1.3"
"@phosphor/signaling" "^1.2.3"

"@phosphor/commands@^1.7.0":
version "1.7.2"
resolved "http://npmrepo/@phosphor%2fcommands/-/commands-1.7.2.tgz#df724f2896ae43c4a3a9e2b5a6445a15e0d60487"
integrity sha512-iSyBIWMHsus323BVEARBhuVZNnVel8USo+FIPaAxGcq+icTSSe6+NtSxVQSmZblGN6Qm4iw6I6VtiSx0e6YDgQ==
dependencies:
"@phosphor/algorithm" "^1.2.0"
"@phosphor/coreutils" "^1.3.1"
"@phosphor/disposable" "^1.3.1"
"@phosphor/domutils" "^1.1.4"
"@phosphor/keyboard" "^1.1.3"
"@phosphor/signaling" "^1.3.1"

"@phosphor/coreutils@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@phosphor/coreutils/-/coreutils-1.3.1.tgz#441e34f42340f7faa742a88b2a181947a88d7226"
Expand All @@ -361,11 +395,24 @@
"@phosphor/algorithm" "^1.1.3"
"@phosphor/signaling" "^1.2.3"

"@phosphor/disposable@^1.3.0", "@phosphor/disposable@^1.3.1":
version "1.3.1"
resolved "http://npmrepo/@phosphor%2fdisposable/-/disposable-1.3.1.tgz#be98fe12bd8c9a4600741cb83b0a305df28628f3"
integrity sha512-0NGzoTXTOizWizK/brKKd5EjJhuuEH4903tLika7q6wl/u0tgneJlTh7R+MBVeih0iNxtuJAfBa3IEY6Qmj+Sw==
dependencies:
"@phosphor/algorithm" "^1.2.0"
"@phosphor/signaling" "^1.3.1"

"@phosphor/domutils@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@phosphor/domutils/-/domutils-1.1.3.tgz#5aeeaefb4bbfcc7c0942e5287a29d3c7f2b1a2bc"
integrity sha512-5CtLAhURQXXHhNXfQydDk/luG1cDVnhlu/qw7gz8/9pht0KXIAmNg/M0LKxx2oJ9+YMNCLVWxAnHAU0yrDpWSA==

"@phosphor/domutils@^1.1.4":
version "1.1.4"
resolved "http://npmrepo/@phosphor%2fdomutils/-/domutils-1.1.4.tgz#4c6aecf7902d3793b45db325319340e0a0b5543b"
integrity sha512-ivwq5TWjQpKcHKXO8PrMl+/cKqbgxPClPiCKc1gwbMd+6hnW5VLwNG0WBzJTxCzXK43HxX18oH+tOZ3E04wc3w==

"@phosphor/dragdrop@^1.3.3":
version "1.3.3"
resolved "https://registry.yarnpkg.com/@phosphor/dragdrop/-/dragdrop-1.3.3.tgz#9487d27a6eb8cd54bfe6d91eaffc9d0852817b61"
Expand Down Expand Up @@ -399,6 +446,13 @@
dependencies:
"@phosphor/algorithm" "^1.1.3"

"@phosphor/signaling@^1.3.0", "@phosphor/signaling@^1.3.1":
version "1.3.1"
resolved "http://npmrepo/@phosphor%2fsignaling/-/signaling-1.3.1.tgz#1cd10b069bdb2c9adb3ba74245b30141e5afc2d7"
integrity sha512-Eq3wVCPQAhUd9+gUGaYygMr+ov7dhSGblSBXiDzpZlSIfa8OVD4P3cCvYXr/acDTNmZ/gHTcSFO8/n3rDkeXzg==
dependencies:
"@phosphor/algorithm" "^1.2.0"

"@phosphor/virtualdom@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@phosphor/virtualdom/-/virtualdom-1.1.3.tgz#33ddebc710ad5bd136fd5f61d7adb4fa14e781e0"
Expand Down