Skip to content

Commit 24739c4

Browse files
committed
[kernel_exec_on_cells] make shift-click on button autoformat all cells
as discussed in #1202 (comment)
1 parent 39049a6 commit 24739c4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/jupyter_contrib_nbextensions/nbextensions/code_prettify/kernel_exec_on_cell.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,16 @@ define([
185185
KernelExecOnCells.prototype.add_toolbar_button = function() {
186186
if ($('#' + this.mod_name + '_button').length < 1) {
187187
var button_group_id = this.mod_name + '_button';
188-
Jupyter.toolbar.add_buttons_group(
189-
[this.cfg.actions.process_selected.name], button_group_id);
188+
var that = this;
189+
Jupyter.toolbar.add_buttons_group([{
190+
label: this.cfg.kbd_shortcut_text + ' selected cell(s) (add shift for all cells)',
191+
icon: this.cfg.button_icon,
192+
callback: function(evt) {
193+
that.autoformat_cells(
194+
evt.shiftKey ? Jupyter.notebook.get_cells().map(function (cell, idx) { return idx; }) : undefined
195+
);
196+
},
197+
}], button_group_id);
190198
}
191199
};
192200

@@ -224,12 +232,7 @@ define([
224232
help_index: 'yf',
225233
icon: that.cfg.button_icon,
226234
handler: function(evt) {
227-
var indices = [],
228-
N = Jupyter.notebook.ncells();
229-
for (var i = 0; i < N; i++) {
230-
indices.push(i);
231-
}
232-
that.autoformat_cells(indices);
235+
that.autoformat_cells(Jupyter.notebook.get_cells().map(function (cell, idx) { return idx; }));
233236
},
234237
};
235238

0 commit comments

Comments
 (0)