Skip to content

Commit e19f2a9

Browse files
authored
Moving cells and debug prompt fix (#32)
* add moving cell commands, change to focus selector to fix debug prompt select * v0.5.0 * jupyter command shortcut for moving cells
1 parent bc14ba4 commit e19f2a9

File tree

5 files changed

+62
-18
lines changed

5 files changed

+62
-18
lines changed

History.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# History
22

3+
## 0.5.0 / 2018-03-27
4+
5+
* add moving cell commands
6+
* Add delete/yank/paste cell commands (#28)
7+
* select first and last cell shortcuts (#24)
8+
* change to focus selector to fix debug prompt select
9+
310
## 0.4.1 / 2018-02-14
411

512
* Ctrl-J and Ctrl-K execute markdown when leaving the cell.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Shortcuts this extension introduces:
4343
| Ctrl-K | Select Cell Above |
4444
| Ctrl-O, G | Select First Cell |
4545
| Ctrl-O, Ctrl-G | Select Last Cell |
46+
| Ctrl-E | Move Cell Down |
47+
| Ctrl-Y | Move Cell Up |
4648
| Command/Ctrl-1 | Code Cell Mode |
4749
| Command/Ctrl-2 | Markdown Cell Mode |
4850
| Command/Ctrl-3 | Raw Cell Mode |
@@ -61,6 +63,8 @@ Shortcuts this extension introduces:
6163
| O | Insert Cell |
6264
| Shift-O | Insert Cell Above |
6365
| U | Undo Cell Action |
66+
| Ctrl-E | Move Cells Down |
67+
| Ctrl-Y | Move Cells Up |
6468

6569
## Prerequisites
6670

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab_vim",
3-
"version": "0.4.2-dev",
3+
"version": "0.5.0",
44
"description": "Code cell vim bindings",
55
"author": "Jacques Kvam",
66
"main": "lib/index.js",
@@ -39,6 +39,8 @@
3939
"@jupyterlab/cells": "^0.15.4",
4040
"@jupyterlab/notebook": "^0.15.4",
4141
"@phosphor/commands": "^1.4.0",
42+
"@phosphor/coreutils": "^1.3.0",
43+
"@phosphor/domutils": "^1.1.2",
4244
"@types/codemirror": "^0.0.55"
4345
},
4446
"devDependencies": {

src/index.ts

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,20 @@ import {
2020
ReadonlyJSONObject
2121
} from '@phosphor/coreutils';
2222

23+
import {
24+
ElementExt
25+
} from '@phosphor/domutils';
26+
2327
import '../style/index.css';
2428

2529
/**
2630
* Initialization data for the jupyterlab_vim extension.
2731
*/
2832
const extension: JupyterLabPlugin<void> = {
29-
id: 'jupyterlab_vim',
30-
autoStart: true,
31-
activate: activateCellVim,
32-
requires: [INotebookTracker]
33+
id: 'jupyterlab_vim',
34+
autoStart: true,
35+
activate: activateCellVim,
36+
requires: [INotebookTracker]
3337
};
3438

3539
class VimCell {
@@ -155,6 +159,15 @@ class VimCell {
155159
{ forward: true, linewise: true },
156160
{ context: 'normal' }
157161
);
162+
163+
lvim.defineAction('moveCellDown', (cm: any, actionArgs: any) => {
164+
commands.execute('notebook:move-cell-down');
165+
});
166+
lvim.defineAction('moveCellUp', (cm: any, actionArgs: any) => {
167+
commands.execute('notebook:move-cell-up');
168+
});
169+
lvim.mapCommand('<C-e>', 'action', 'moveCellDown', {}, {extra: 'normal'});
170+
lvim.mapCommand('<C-y>', 'action', 'moveCellUp', {}, {extra: 'normal'});
158171
}
159172
}
160173

@@ -308,6 +321,10 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
308321
if (current) {
309322
current.notebook.activeCellIndex = 0;
310323
current.notebook.deselectAll();
324+
ElementExt.scrollIntoViewIfNeeded(
325+
current.notebook.node,
326+
current.notebook.activeCell.node
327+
);
311328
}
312329
},
313330
isEnabled
@@ -320,6 +337,10 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
320337
if (current) {
321338
current.notebook.activeCellIndex = current.notebook.widgets.length - 1;
322339
current.notebook.deselectAll();
340+
ElementExt.scrollIntoViewIfNeeded(
341+
current.notebook.node,
342+
current.notebook.activeCell.node
343+
);
323344
}
324345
},
325346
isEnabled
@@ -356,7 +377,7 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
356377
command: 'notebook:extend-marked-cells-below'
357378
});
358379
commands.addKeyBinding({
359-
selector: '.jp-Notebook.jp-mod-commandMode',
380+
selector: '.jp-Notebook:focus',
360381
keys: ['Ctrl Shift J'],
361382
command: 'notebook:extend-marked-cells-below'
362383
});
@@ -366,7 +387,7 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
366387
command: 'notebook:extend-marked-cells-above'
367388
});
368389
commands.addKeyBinding({
369-
selector: '.jp-Notebook.jp-mod-commandMode',
390+
selector: '.jp-Notebook:focus',
370391
keys: ['Ctrl Shift K'],
371392
command: 'notebook:extend-marked-cells-above'
372393
});
@@ -417,7 +438,7 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
417438
command: 'notebook:enter-command-mode'
418439
});
419440
commands.addKeyBinding({
420-
selector: '.jp-Notebook.jp-mod-commandMode',
441+
selector: '.jp-Notebook:focus',
421442
keys: ['Shift M'],
422443
command: 'merge-and-edit'
423444
});
@@ -447,50 +468,60 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
447468
command: 'select-last-cell'
448469
});
449470
commands.addKeyBinding({
450-
selector: '.jp-Notebook.jp-mod-commandMode',
471+
selector: '.jp-Notebook:focus',
451472
keys: ['G', 'G'],
452473
command: 'select-first-cell'
453474
});
454475
commands.addKeyBinding({
455-
selector: '.jp-Notebook.jp-mod-commandMode',
476+
selector: '.jp-Notebook:focus',
456477
keys: ['Shift G'],
457478
command: 'select-last-cell'
458479
});
459480
commands.addKeyBinding({
460-
selector: '.jp-Notebook.jp-mod-commandMode',
481+
selector: '.jp-Notebook:focus',
461482
keys: ['Y', 'Y'],
462483
command: 'notebook:copy-cell'
463484
});
464485
commands.addKeyBinding({
465-
selector: '.jp-Notebook.jp-mod-commandMode',
486+
selector: '.jp-Notebook:focus',
466487
keys: ['D', 'D'],
467488
command: 'notebook:cut-cell'
468489
});
469490
commands.addKeyBinding({
470-
selector: '.jp-Notebook.jp-mod-commandMode',
491+
selector: '.jp-Notebook:focus',
471492
keys: ['Shift P'],
472493
command: 'notebook:paste-cell-above'
473494
});
474495
commands.addKeyBinding({
475-
selector: '.jp-Notebook.jp-mod-commandMode',
496+
selector: '.jp-Notebook:focus',
476497
keys: ['P'],
477498
command: 'notebook:paste-cell-below'
478499
});
479500
commands.addKeyBinding({
480-
selector: '.jp-Notebook.jp-mod-commandMode',
501+
selector: '.jp-Notebook:focus',
481502
keys: ['O'],
482503
command: 'notebook:insert-cell-below'
483504
});
484505
commands.addKeyBinding({
485-
selector: '.jp-Notebook.jp-mod-commandMode',
506+
selector: '.jp-Notebook:focus',
486507
keys: ['Shift O'],
487508
command: 'notebook:insert-cell-above'
488509
});
489510
commands.addKeyBinding({
490-
selector: '.jp-Notebook.jp-mod-commandMode',
511+
selector: '.jp-Notebook:focus',
491512
keys: ['U'],
492513
command: 'notebook:undo-cell-action'
493514
});
515+
commands.addKeyBinding({
516+
selector: '.jp-Notebook:focus',
517+
keys: ['Ctrl E'],
518+
command: 'notebook:move-cell-down'
519+
});
520+
commands.addKeyBinding({
521+
selector: '.jp-Notebook:focus',
522+
keys: ['Ctrl Y'],
523+
command: 'notebook:move-cell-up'
524+
});
494525

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

0 commit comments

Comments
 (0)