Skip to content

Commit 9de0813

Browse files
authored
center cell (#33)
1 parent a882d42 commit 9de0813

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Shortcuts this extension introduces:
3131
| Chord | Action |
3232
| ----- | ------- |
3333
| Ctrl-O, U | Undo Cell Action |
34+
| - | Split Cell at Cursor |
3435
| Ctrl-O, - | Split Cell at Cursor |
3536
| Ctrl-O, D | Cut Cell |
3637
| Ctrl-O, Y | Copy Cell |
@@ -45,6 +46,7 @@ Shortcuts this extension introduces:
4546
| Ctrl-O, Ctrl-G | Select Last Cell |
4647
| Ctrl-E | Move Cell Down |
4748
| Ctrl-Y | Move Cell Up |
49+
| Ctrl-O, Z, Z | Center Cell |
4850
| Command/Ctrl-1 | Code Cell Mode |
4951
| Command/Ctrl-2 | Markdown Cell Mode |
5052
| Command/Ctrl-3 | Raw Cell Mode |
@@ -65,6 +67,7 @@ Shortcuts this extension introduces:
6567
| U | Undo Cell Action |
6668
| Ctrl-E | Move Cells Down |
6769
| Ctrl-Y | Move Cells Up |
70+
| Z, Z | Center Cell |
6871

6972
## Prerequisites
7073

src/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ class VimCell {
175175
});
176176
lvim.mapCommand('<C-e>', 'action', 'moveCellDown', {}, {extra: 'normal'});
177177
lvim.mapCommand('<C-y>', 'action', 'moveCellUp', {}, {extra: 'normal'});
178+
lvim.defineAction('splitCell', (cm: any, actionArgs: any) => {
179+
commands.execute('notebook:split-cell-at-cursor');
180+
});
181+
lvim.mapCommand('-', 'action', 'splitCell', {}, {extra: 'normal'});
178182
}
179183
}
180184

@@ -352,6 +356,18 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
352356
},
353357
isEnabled
354358
});
359+
commands.addCommand('center-cell', {
360+
label: 'Center Cell',
361+
execute: args => {
362+
const current = getCurrent(args);
363+
364+
if (current) {
365+
let er = current.notebook.activeCell.inputArea.node.getBoundingClientRect();
366+
current.notebook.scrollToPosition(er.bottom, 0);
367+
}
368+
},
369+
isEnabled
370+
});
355371

356372
commands.addKeyBinding({
357373
selector: '.jp-Notebook.jp-mod-editMode',
@@ -529,6 +545,16 @@ function activateCellVim(app: JupyterLab, tracker: INotebookTracker): Promise<vo
529545
keys: ['Ctrl Y'],
530546
command: 'notebook:move-cell-up'
531547
});
548+
commands.addKeyBinding({
549+
selector: '.jp-Notebook:focus',
550+
keys: ['Z', 'Z'],
551+
command: 'center-cell'
552+
});
553+
commands.addKeyBinding({
554+
selector: '.jp-Notebook.jp-mod-editMode',
555+
keys: ['Ctrl O', 'Z', 'Z'],
556+
command: 'center-cell'
557+
});
532558

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

0 commit comments

Comments
 (0)