@@ -20,16 +20,20 @@ import {
2020 ReadonlyJSONObject
2121} from '@phosphor/coreutils' ;
2222
23+ import {
24+ ElementExt
25+ } from '@phosphor/domutils' ;
26+
2327import '../style/index.css' ;
2428
2529/**
2630 * Initialization data for the jupyterlab_vim extension.
2731 */
2832const 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
3539class 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