Skip to content

Commit e41b62b

Browse files
committed
[collapsible_headings] add (un)collapse all actions & shortcuts
1 parent d7f4b63 commit e41b62b

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/collapsible_headings.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ Parameters:
6262
description: Command-mode shortcut to uncollapse (expand) the selected heading cell
6363
input_type: hotkey
6464
default: right
65+
- name: collapsible_headings.shortcuts.collapse_all
66+
description: Command-mode shortcut to collapse all heading cells
67+
input_type: hotkey
68+
default: ctrl-shift-left
69+
- name: collapsible_headings.shortcuts.uncollapse_all
70+
description: Command-mode shortcut to uncollapse (expand) all heading cells
71+
input_type: hotkey
72+
default: ctrl-shift-right
6573
- name: collapsible_headings.shortcuts.select
6674
description: Command-mode shortcut to select all cells in the selected heading cell's section
6775
input_type: hotkey

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ define(['jquery', 'require'], function ($, require) {
2525
use_shortcuts : true,
2626
shortcuts: {
2727
collapse: 'left',
28+
collapse_all: 'ctrl-shift-left',
2829
uncollapse: 'right',
30+
uncollapse_all: 'ctrl-shift-right',
2931
select: 'shift-right',
3032
insert_above: 'shift-a',
3133
insert_below: 'shift-b',
@@ -644,6 +646,27 @@ define(['jquery', 'require'], function ($, require) {
644646
'collapse_heading', mod_name
645647
);
646648

649+
action_names.collapse_all = Jupyter.keyboard_manager.actions.register({
650+
handler : function (env) {
651+
env.notebook.get_cells().forEach(function (c, idx, arr) {
652+
toggle_heading(c, true);
653+
});
654+
var cell = env.notebook.get_selected_cell();
655+
if (cell.element.is(':hidden')) {
656+
cell = find_header_cell(cell, function (c) { return c.element.is(':visible'); });
657+
if (cell !== undefined) {
658+
Jupyter.notebook.select(Jupyter.notebook.find_cell_index(cell));
659+
cell.focus_cell();
660+
}
661+
}
662+
},
663+
help : "Collapse all heading cells' sections",
664+
icon : params.toggle_closed_icon,
665+
help_index: 'c2'
666+
},
667+
'collapse_all_headings', mod_name
668+
);
669+
647670
action_names.uncollapse = Jupyter.keyboard_manager.actions.register({
648671
handler : function (env) {
649672
var cell = env.notebook.get_selected_cell();
@@ -664,11 +687,25 @@ define(['jquery', 'require'], function ($, require) {
664687
},
665688
help : "Un-collapse (expand) the selected heading cell's section",
666689
icon : params.toggle_open_icon,
667-
help_index: 'c2'
690+
help_index: 'c3'
668691
},
669692
'uncollapse_heading', mod_name
670693
);
671694

695+
action_names.uncollapse_all = Jupyter.keyboard_manager.actions.register({
696+
handler : function (env) {
697+
env.notebook.get_cells().forEach(function (c, idx, arr) {
698+
toggle_heading(c, false);
699+
});
700+
env.notebook.get_selected_cell().focus_cell();
701+
},
702+
help : "Un-collapse (expand) all heading cells' sections",
703+
icon : params.toggle_open_icon,
704+
help_index: 'c4'
705+
},
706+
'uncollapse_all_headings', mod_name
707+
);
708+
672709
action_names.select = Jupyter.keyboard_manager.actions.register({
673710
handler : function (env) {
674711
var cell = env.notebook.get_selected_cell();

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ the nbextensions config page:
2121

2222
* Command-mode keyboard shortcuts, (enabled by default, and set to left and
2323
right arrow keys to collapse/expand sections, or go to the previous/next
24-
heading, plus shift-right to select a heading cell's section).
24+
heading, plus shift-right to select a heading cell's section, shift-a/b to
25+
insert a heading above/below the current cell, ctrl-shift-left and
26+
ctrl-shift-right to collapse/uncollapse all headings).
2527
Bindings are also configurable from the config page
2628
* A toggle control in the input prompt area of each heading cell (as seen in
2729
the screenshot below, enabled by default)

0 commit comments

Comments
 (0)