Socket
Socket
Sign inDemoInstall

@axlair/jupyterlab_vim

Package Overview
Dependencies
200
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.12.4 to 0.13.2

5

History.md
# History
## 0.13.0 / 2020-12-10
* Support JupyterLab 3+
* Set up eslint and prettier
## 0.12.4 / 2020-05-20

@@ -4,0 +9,0 @@

2

lib/index.d.ts
import { JupyterFrontEndPlugin } from '@jupyterlab/application';
import '../style/index.css';
import 'codemirror/keymap/vim.js';
/**

@@ -5,0 +3,0 @@ * Initialization data for the jupyterlab_vim extension.

@@ -1,10 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CodeMirror = require("codemirror");
const notebook_1 = require("@jupyterlab/notebook");
const domutils_1 = require("@lumino/domutils");
require("../style/index.css");
// Previously the vim keymap was loaded by JupyterLab, but now
// it is lazy loaded, so we have to load it explicitly
require("codemirror/keymap/vim.js");
import { INotebookTracker, NotebookActions } from '@jupyterlab/notebook';
import { ICodeMirror } from '@jupyterlab/codemirror';
import { ElementExt } from '@lumino/domutils';
/**

@@ -21,8 +15,9 @@ * A boolean indicating whether the platform is Mac.

activate: activateCellVim,
requires: [notebook_1.INotebookTracker]
requires: [INotebookTracker, ICodeMirror]
};
class VimCell {
constructor(app, tracker) {
constructor(app, tracker, cm) {
this._tracker = tracker;
this._app = app;
this._cm = cm;
this._onActiveCellChanged();

@@ -32,29 +27,26 @@ this._tracker.activeCellChanged.connect(this._onActiveCellChanged, this);

_onActiveCellChanged() {
// if (this._prevActive && !this._prevActive.isDisposed) {
// this._prevActive.metadata.changed.disconnect(this._onMetadataChanged, this);
// }
let activeCell = this._tracker.activeCell;
const activeCell = this._tracker.activeCell;
if (activeCell !== null) {
const { commands } = this._app;
let editor = activeCell.editor;
const editor = activeCell.editor;
editor.setOption('keyMap', 'vim');
let extraKeys = editor.getOption('extraKeys') || {};
extraKeys['Esc'] = CodeMirror.prototype.leaveInsertMode;
const extraKeys = editor.getOption('extraKeys') || {};
extraKeys['Esc'] = this._cm.prototype.leaveInsertMode;
if (!IS_MAC) {
extraKeys['Ctrl-C'] = false;
}
CodeMirror.prototype.save = () => {
this._cm.prototype.save = () => {
commands.execute('docmanager:save');
};
editor.setOption('extraKeys', extraKeys);
let lcm = CodeMirror;
let lvim = lcm.Vim;
lvim.defineEx('quit', 'q', function (cm) {
const lcm = this._cm;
const lvim = lcm.Vim;
lvim.defineEx('quit', 'q', (cm) => {
commands.execute('notebook:enter-command-mode');
});
CodeMirror.Vim.handleKey(editor.editor, '<Esc>');
this._cm.Vim.handleKey(editor.editor, '<Esc>');
lvim.defineMotion('moveByLinesOrCell', (cm, head, motionArgs, vim) => {
let cur = head;
const cur = head;
let endCh = cur.ch;
let currentCell = activeCell;
const currentCell = activeCell;
// TODO: these references will be undefined

@@ -73,2 +65,3 @@ // Depending what our last motion was, we may want to do different

// JUPYTER PATCH: add our custom method to the motion cases
// eslint-disable-next-line no-fallthrough
case 'moveByLinesOrCell':

@@ -80,6 +73,8 @@ endCh = vim.lastHPos;

}
let repeat = motionArgs.repeat + (motionArgs.repeatOffset || 0);
let line = motionArgs.forward ? cur.line + repeat : cur.line - repeat;
let first = cm.firstLine();
let last = cm.lastLine();
const repeat = motionArgs.repeat + (motionArgs.repeatOffset || 0);
const line = motionArgs.forward
? cur.line + repeat
: cur.line - repeat;
const first = cm.firstLine();
const last = cm.lastLine();
// Vim cancels linewise motions that start on an edge and move beyond

@@ -109,27 +104,7 @@ // that edge. It does not cancel motions that do not start on an edge.

}
// ns.notebook.edit_mode();
// var new_cell = ns.notebook.get_selected_cell();
// if (currentCell !== new_cell && !!new_cell) {
// // The selected cell has moved. Move the cursor at very end
// var cm2 = new_cell.code_mirror;
// cm2.setCursor({
// ch: cm2.getCursor().ch,
// line: motionArgs.forward ? cm2.firstLine() : cm2.lastLine()
// });
// // Perform remaining repeats
// repeat = motionArgs.forward ? line - last : first - line;
// repeat -= 1;
// if (Math.abs(repeat) > 0) {
// CodeMirror.Vim.handleKey(cm2, repeat + key); // e.g. 4j, 6k, etc.
// }
// }
return;
}
// JUPYTER PATCH END
// if (motionArgs.toFirstChar){
// endCh = findFirstNonWhiteSpaceCharacter(cm.getLine(line));
// vim.lastHPos = endCh;
// }
vim.lastHSPos = cm.charCoords(CodeMirror.Pos(line, endCh), 'div').left;
return CodeMirror.Pos(line, endCh);
vim.lastHSPos = cm.charCoords(this._cm.Pos(line, endCh), 'div').left;
return this._cm.Pos(line, endCh);
});

@@ -153,5 +128,7 @@ lvim.mapCommand('k', 'motion', 'moveByLinesOrCell', { forward: false, linewise: true }, { context: 'normal' });

}
function activateCellVim(app, tracker) {
Promise.all([app.restored]).then(([args]) => {
function activateCellVim(app, tracker, jlabCodeMirror) {
Promise.all([app.restored]).then(async ([args]) => {
const { commands, shell } = app;
await jlabCodeMirror.ensureVimKeymap();
const CodeMirror = jlabCodeMirror.CodeMirror;
function getCurrent(args) {

@@ -166,4 +143,4 @@ const widget = tracker.currentWidget;

function isEnabled() {
return tracker.currentWidget !== null &&
tracker.currentWidget === app.shell.currentWidget;
return (tracker.currentWidget !== null &&
tracker.currentWidget === app.shell.currentWidget);
}

@@ -176,3 +153,3 @@ commands.addCommand('run-select-next-edit', {

const { context, content } = current;
notebook_1.NotebookActions.runAndAdvance(content, context.sessionContext);
NotebookActions.runAndAdvance(content, context.sessionContext);
current.content.mode = 'edit';

@@ -189,3 +166,3 @@ }

const { context, content } = current;
notebook_1.NotebookActions.run(content, context.sessionContext);
NotebookActions.run(content, context.sessionContext);
current.content.mode = 'edit';

@@ -202,3 +179,3 @@ }

const { content } = current;
notebook_1.NotebookActions.cut(content);
NotebookActions.cut(content);
content.mode = 'edit';

@@ -215,3 +192,3 @@ }

const { content } = current;
notebook_1.NotebookActions.copy(content);
NotebookActions.copy(content);
content.mode = 'edit';

@@ -228,3 +205,3 @@ }

const { content } = current;
notebook_1.NotebookActions.paste(content, 'below');
NotebookActions.paste(content, 'below');
content.mode = 'edit';

@@ -241,3 +218,3 @@ }

const { content } = current;
notebook_1.NotebookActions.mergeCells(content);
NotebookActions.mergeCells(content);
current.content.mode = 'edit';

@@ -255,3 +232,3 @@ }

if (content.activeCell !== null) {
let editor = content.activeCell.editor;
const editor = content.activeCell.editor;
current.content.mode = 'edit';

@@ -271,3 +248,3 @@ CodeMirror.Vim.handleKey(editor.editor, 'i');

if (content.activeCell !== null) {
let editor = content.activeCell.editor;
const editor = content.activeCell.editor;
CodeMirror.Vim.handleKey(editor.editor, '<Esc>');

@@ -289,3 +266,3 @@ }

}
return notebook_1.NotebookActions.selectBelow(current.content);
return NotebookActions.selectBelow(current.content);
}

@@ -305,3 +282,3 @@ },

}
return notebook_1.NotebookActions.selectAbove(current.content);
return NotebookActions.selectAbove(current.content);
}

@@ -320,3 +297,3 @@ },

if (content.activeCell !== null) {
domutils_1.ElementExt.scrollIntoViewIfNeeded(content.node, content.activeCell.node);
ElementExt.scrollIntoViewIfNeeded(content.node, content.activeCell.node);
}

@@ -336,3 +313,3 @@ }

if (content.activeCell !== null) {
domutils_1.ElementExt.scrollIntoViewIfNeeded(content.node, content.activeCell.node);
ElementExt.scrollIntoViewIfNeeded(content.node, content.activeCell.node);
}

@@ -347,4 +324,4 @@ }

const current = getCurrent(args);
if (current && current.content.activeCell != null) {
let er = current.content.activeCell.inputArea.node.getBoundingClientRect();
if (current && current.content.activeCell !== null) {
const er = current.content.activeCell.inputArea.node.getBoundingClientRect();
current.content.scrollToPosition(er.bottom, 0);

@@ -577,6 +554,6 @@ }

// tslint:disable:no-unused-expression
new VimCell(app, tracker);
new VimCell(app, tracker, CodeMirror);
});
return Promise.resolve();
}
exports.default = extension;
export default extension;
{
"name": "@axlair/jupyterlab_vim",
"version": "0.12.4",
"version": "0.13.2",
"description": "Code cell vim bindings",

@@ -24,7 +24,18 @@ "author": "Axel Fahy",

"scripts": {
"build": "tsc",
"clean": "rimraf lib",
"lint": "tslint",
"prepare": "npm run build",
"watch": "tsc -w"
"build": "jlpm run build:lib && jlpm run build:labextension:dev",
"build:prod": "jlpm run build:lib && jlpm run build:labextension",
"build:labextension": "jupyter labextension build .",
"build:labextension:dev": "jupyter labextension build --development True .",
"build:lib": "tsc",
"clean": "jlpm run clean:lib",
"clean:lib": "rimraf lib tsconfig.tsbuildinfo",
"clean:labextension": "rimraf jupyterlab_vim/labextension",
"clean:all": "jlpm run clean:lib && jlpm run clean:labextension",
"eslint": "eslint . --ext .ts,.tsx --fix",
"eslint:check": "eslint . --ext .ts,.tsx",
"install:extension": "jupyter labextension develop --overwrite .",
"prepare": "jlpm run clean && jlpm run build:prod",
"watch": "run-p watch:src watch:labextension",
"watch:src": "tsc -w",
"watch:labextension": "jupyter labextension watch ."
},

@@ -36,20 +47,29 @@ "files": [

"jupyterlab": {
"extension": true
"extension": true,
"outputDir": "jupyterlab_vim/labextension"
},
"dependencies": {
"@jupyterlab/application": "^2.0.1",
"@jupyterlab/cells": "^2.0.1",
"@jupyterlab/codemirror": "^2.0.1",
"@jupyterlab/notebook": "^2.0.1",
"@lumino/commands": "^1.10.1",
"@lumino/coreutils": "^1.4.2",
"@lumino/domutils": "^1.1.7",
"@jupyterlab/application": "^3.0.0-rc.13",
"@jupyterlab/cells": "^3.0.0-rc.13",
"@jupyterlab/codemirror": "^3.0.0-rc.13",
"@jupyterlab/notebook": "^3.0.0-rc.13",
"@lumino/commands": "^1.12.0",
"@lumino/coreutils": "^1.5.3",
"@lumino/domutils": "^1.2.3",
"@types/codemirror": "^0.0.87",
"react": "16.9.0"
"react": "^17.0.1"
},
"devDependencies": {
"rimraf": "^2.6.2",
"@jupyterlab/builder": "^3.0.0-rc.2",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"eslint": "^7.5.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
"npm-run-all": "^4.1.5",
"prettier": "^1.19.0",
"rimraf": "^3.0.2",
"tslint": "^6.1.2",
"typescript": "^3.9.3"
"typescript": "~4.0.3"
}
}

@@ -24,7 +24,10 @@ # jupyterlab-vim

## Install
### Prerequisites
### For jupyterlab 3+
* JupyterLab 2.0
```bash
pip install jupyterlab_vim
```
### Install or upgrade
### For jupyterlab 2
#### Install or upgrade

@@ -35,3 +38,3 @@ ```bash

### Uninstall
#### Uninstall

@@ -111,17 +114,46 @@ ```bash

## Development
### Development install
For a development install (requires npm version 4 or later), do the following in the repository directory. **Please note**, you need to make sure that you satisfy all the prerequisites, i.e. the JupyterLab version.
Note: You will need NodeJS to build the extension package. To install with `conda` do:
```
conda install -c conda-forge nodejs
```
The `jlpm` command is JupyterLab's pinned version of
[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
`yarn` or `npm` in lieu of `jlpm` below.
```bash
jlpm install
# Clone the repo to your local environment
# Change directory to the jupyterlab_vim directory
# Install package in development mode
pip install jupyter_packaging
pip install -e .
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Rebuild extension Typescript source after making changes
jlpm run build
jupyter labextension link .
```
To rebuild the package and the JupyterLab app:
You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
```bash
jlpm run build
jupyter lab build
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm run watch
# Run JupyterLab in another terminal
jupyter lab
```
With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
By default, the `jlpm run build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
```bash
jupyter lab build --minimize=False
```
### Uninstall
```bash
pip uninstall jupyterlab_vim
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc