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

WIP: settings #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
33 changes: 32 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions schema/vim.json
Original file line number Diff line number Diff line change
@@ -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"
}
23 changes: 16 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
MarkdownCell
} from '@jupyterlab/cells';

import {
ISettingRegistry
} from '@jupyterlab/coreutils';

import {
CodeMirrorEditor
} from '@jupyterlab/codemirror';
Expand All @@ -35,10 +39,10 @@ const IS_MAC = !!navigator.platform.match(/Mac/i);
* Initialization data for the jupyterlab_vim extension.
*/
const extension: JupyterLabPlugin<void> = {
id: 'jupyterlab_vim',
id: 'jupyterlab_vim:vim',
autoStart: true,
activate: activateCellVim,
requires: [INotebookTracker]
requires: [INotebookTracker, ISettingRegistry]
};

class VimCell {
Expand Down Expand Up @@ -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, '<Esc>');
lvim.handleKey(editor.editor, '<Esc>');
lvim.defineMotion('moveByLinesOrCell', (cm: any, head: any, motionArgs: any, vim: any) => {
let cur = head;
let endCh = cur.ch;
Expand Down Expand Up @@ -186,10 +189,16 @@ class VimCell {
private _app: JupyterLab;
}

function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<void> {
function activateCellVim(app: JupyterLab, tracker: INotebookTracker, settingRegistry: ISettingRegistry): Promise<void> {
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;
Expand Down