Skip to content

Commit

Permalink
Moving cells and debug prompt fix (#32)
Browse files Browse the repository at this point in the history
* add moving cell commands, change to focus selector to fix debug prompt select

* v0.5.0

* jupyter command shortcut for moving cells
  • Loading branch information
jwkvam committed Mar 27, 2018
1 parent bc14ba4 commit e19f2a9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# History

## 0.5.0 / 2018-03-27

* add moving cell commands
* Add delete/yank/paste cell commands (#28)
* select first and last cell shortcuts (#24)
* change to focus selector to fix debug prompt select

## 0.4.1 / 2018-02-14

* Ctrl-J and Ctrl-K execute markdown when leaving the cell.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Shortcuts this extension introduces:
| Ctrl-K | Select Cell Above |
| Ctrl-O, G | Select First Cell |
| Ctrl-O, Ctrl-G | Select Last Cell |
| Ctrl-E | Move Cell Down |
| Ctrl-Y | Move Cell Up |
| Command/Ctrl-1 | Code Cell Mode |
| Command/Ctrl-2 | Markdown Cell Mode |
| Command/Ctrl-3 | Raw Cell Mode |
Expand All @@ -61,6 +63,8 @@ Shortcuts this extension introduces:
| O | Insert Cell |
| Shift-O | Insert Cell Above |
| U | Undo Cell Action |
| Ctrl-E | Move Cells Down |
| Ctrl-Y | Move Cells Up |

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jupyterlab_vim",
"version": "0.4.2-dev",
"version": "0.5.0",
"description": "Code cell vim bindings",
"author": "Jacques Kvam",
"main": "lib/index.js",
Expand Down Expand Up @@ -39,6 +39,8 @@
"@jupyterlab/cells": "^0.15.4",
"@jupyterlab/notebook": "^0.15.4",
"@phosphor/commands": "^1.4.0",
"@phosphor/coreutils": "^1.3.0",
"@phosphor/domutils": "^1.1.2",
"@types/codemirror": "^0.0.55"
},
"devDependencies": {
Expand Down
63 changes: 47 additions & 16 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ import {
ReadonlyJSONObject
} from '@phosphor/coreutils';

import {
ElementExt
} from '@phosphor/domutils';

import '../style/index.css';

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

class VimCell {
Expand Down Expand Up @@ -155,6 +159,15 @@ class VimCell {
{ forward: true, linewise: true },
{ context: 'normal' }
);

lvim.defineAction('moveCellDown', (cm: any, actionArgs: any) => {
commands.execute('notebook:move-cell-down');
});
lvim.defineAction('moveCellUp', (cm: any, actionArgs: any) => {
commands.execute('notebook:move-cell-up');
});
lvim.mapCommand('<C-e>', 'action', 'moveCellDown', {}, {extra: 'normal'});
lvim.mapCommand('<C-y>', 'action', 'moveCellUp', {}, {extra: 'normal'});
}
}

Expand Down Expand Up @@ -308,6 +321,10 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
if (current) {
current.notebook.activeCellIndex = 0;
current.notebook.deselectAll();
ElementExt.scrollIntoViewIfNeeded(
current.notebook.node,
current.notebook.activeCell.node
);
}
},
isEnabled
Expand All @@ -320,6 +337,10 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
if (current) {
current.notebook.activeCellIndex = current.notebook.widgets.length - 1;
current.notebook.deselectAll();
ElementExt.scrollIntoViewIfNeeded(
current.notebook.node,
current.notebook.activeCell.node
);
}
},
isEnabled
Expand Down Expand Up @@ -356,7 +377,7 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
command: 'notebook:extend-marked-cells-below'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Ctrl Shift J'],
command: 'notebook:extend-marked-cells-below'
});
Expand All @@ -366,7 +387,7 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
command: 'notebook:extend-marked-cells-above'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Ctrl Shift K'],
command: 'notebook:extend-marked-cells-above'
});
Expand Down Expand Up @@ -417,7 +438,7 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
command: 'notebook:enter-command-mode'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Shift M'],
command: 'merge-and-edit'
});
Expand Down Expand Up @@ -447,50 +468,60 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
command: 'select-last-cell'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['G', 'G'],
command: 'select-first-cell'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Shift G'],
command: 'select-last-cell'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Y', 'Y'],
command: 'notebook:copy-cell'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['D', 'D'],
command: 'notebook:cut-cell'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Shift P'],
command: 'notebook:paste-cell-above'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['P'],
command: 'notebook:paste-cell-below'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['O'],
command: 'notebook:insert-cell-below'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['Shift O'],
command: 'notebook:insert-cell-above'
});
commands.addKeyBinding({
selector: '.jp-Notebook.jp-mod-commandMode',
selector: '.jp-Notebook:focus',
keys: ['U'],
command: 'notebook:undo-cell-action'
});
commands.addKeyBinding({
selector: '.jp-Notebook:focus',
keys: ['Ctrl E'],
command: 'notebook:move-cell-down'
});
commands.addKeyBinding({
selector: '.jp-Notebook:focus',
keys: ['Ctrl Y'],
command: 'notebook:move-cell-up'
});

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

0 comments on commit e19f2a9

Please sign in to comment.