Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit a0eaffa

Browse files
authored
Merge pull request #85 from jwkvam/execute-markdown-when-leaving
RFC: eval markdown when leaving a cell
2 parents 94769bd + bd506ab commit a0eaffa

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lib/codemirror.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ define([
4141
if(line < first || line > last){
4242
var current_cell = ns.notebook.get_selected_cell();
4343
var key = '';
44+
if (current_cell.cell_type == 'markdown') {
45+
current_cell.execute();
46+
}
4447
if (motionArgs.forward) {
4548
ns.notebook.select_next();
4649
key = 'j';

lib/jupyter/actions.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ define([
5959
}
6060
}, 'run-cell-and-select-next', 'vim-binding');
6161

62+
actions.register({
63+
'help': 'run cell, select below',
64+
'handler': function(env, event) {
65+
env.notebook.command_mode();
66+
if (env.notebook.get_selected_cell().cell_type == 'markdown') {
67+
actions.call('jupyter-notebook:run-cell-and-select-next', event, env);
68+
} else {
69+
actions.call('jupyter-notebook:select-next-cell', event, env);
70+
}
71+
env.notebook.edit_mode();
72+
}
73+
}, 'select-next-cell-eval-markdown', 'vim-binding');
74+
75+
actions.register({
76+
'help': 'run cell, select above',
77+
'handler': function(env, event) {
78+
env.notebook.command_mode();
79+
if (env.notebook.get_selected_cell().cell_type == 'markdown') {
80+
actions.call('jupyter-notebook:run-cell', event, env);
81+
}
82+
actions.call('jupyter-notebook:select-previous-cell', event, env);
83+
env.notebook.edit_mode();
84+
}
85+
}, 'select-previous-cell-eval-markdown', 'vim-binding');
86+
6287
actions.register({
6388
'help': 'run selected cells',
6489
'handler': function(env, event) {

lib/jupyter/shortcuts.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ define([
9494
// Repeat operations
9595
'ctrl-y': 'vim-binding:scroll-up',
9696
'ctrl-e': 'vim-binding:scroll-down',
97-
'ctrl-k': 'vim-binding:select-previous-cell', // require C-k unmapping in CodeMirror
98-
'ctrl-j': 'vim-binding:select-next-cell', // require C-j unmapping in CodeMirror
97+
'ctrl-k': 'vim-binding:select-previous-cell-eval-markdown', // require C-k unmapping in CodeMirror
98+
'ctrl-j': 'vim-binding:select-next-cell-eval-markdown', // require C-j unmapping in CodeMirror
9999
'ctrl-shift-k': 'vim-binding:extend-selection-above',
100100
'ctrl-shift-j': 'vim-binding:extend-selection-below',
101101
'ctrl-shift-u': 'vim-binding:scroll-notebook-up',

0 commit comments

Comments
 (0)