From 826b6733ad4a74ed591f1e67eb67c7a1d7727b92 Mon Sep 17 00:00:00 2001 From: Aaron Myatt Date: Mon, 23 Oct 2017 12:46:40 +0800 Subject: [PATCH 1/8] render keyboard shortcuts from KeyboardManager render keyboard shortcuts from KeyboardManager --- notebook/static/notebook/js/menubar.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 36209ca6bf..a93d7a6ee7 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -24,6 +24,7 @@ define([ * options: dictionary * Dictionary of keyword arguments. * notebook: Notebook instance + * render keyboard shortcuts from KeyboardManager * contents: ContentManager instance * events: $(Events) instance * save_widget: SaveWidget instance @@ -37,7 +38,8 @@ define([ this.base_url = options.base_url || utils.get_body_data("baseUrl"); this.selector = selector; this.notebook = options.notebook; - this.actions = this.notebook.keyboard_manager.actions; + this.keyboard_manager = this.notebook.keyboard_manager; + this.actions = this.keyboard_manager.actions; this.contents = options.contents; this.events = options.events; this.save_widget = options.save_widget; @@ -276,9 +278,21 @@ define([ } // Immediately-Invoked Function Expression cause JS. (function(that, id_act, idx){ - that.element.find(idx).click(function(event){ + var el = that.element.find(idx); + el.click(function(event){ that.actions.call(id_act, event); }); + + var keybinding = that.keyboard_manager.command_shortcuts.get_action_shortcut(id_act); + + if(keybinding === undefined) { + keybinding = that.keyboard_manager.edit_shortcuts.get_action_shortcut(id_act); + } + + if(keybinding !== undefined) { + var binding = ''+keybinding+''; + el.children().append(binding); + } })(that, id_act, idx); } From 60910285a4e4d801ce09ce43f0f9b30a5a941398 Mon Sep 17 00:00:00 2001 From: Aaron Myatt Date: Mon, 23 Oct 2017 20:39:18 +0800 Subject: [PATCH 2/8] float menu keybindings to the right --- notebook/static/notebook/less/menubar.less | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notebook/static/notebook/less/menubar.less b/notebook/static/notebook/less/menubar.less index e5209f257b..0a7b54f230 100644 --- a/notebook/static/notebook/less/menubar.less +++ b/notebook/static/notebook/less/menubar.less @@ -146,4 +146,8 @@ ul#help_menu li a{ margin-left: 10px; } +.kb { + float: right; +} + //end submenu From 289c27593033bc11a569c839d1825fac2b97b521 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Thu, 26 Oct 2017 22:00:17 -0700 Subject: [PATCH 3/8] Clean up styling --- notebook/static/notebook/js/menubar.js | 16 ++++++++-------- notebook/static/notebook/less/menubar.less | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index a93d7a6ee7..551cabb5da 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -283,15 +283,15 @@ define([ that.actions.call(id_act, event); }); - var keybinding = that.keyboard_manager.command_shortcuts.get_action_shortcut(id_act); + var keybinding = that.keyboard_manager.command_shortcuts.get_action_shortcut(id_act) || that.keyboard_manager.edit_shortcuts.get_action_shortcut(id_act); - if(keybinding === undefined) { - keybinding = that.keyboard_manager.edit_shortcuts.get_action_shortcut(id_act); - } - - if(keybinding !== undefined) { - var binding = ''+keybinding+''; - el.children().append(binding); + if (keybinding) { + var link_element = el.children('a'); + var text = link_element.text(); + link_element.text(''); + link_element.attr('style', 'display: flex; flex-direction: row; justify-content: space-between; align-items: flex-end;'); + link_element.append('' + text + ''); + link_element.append('' + keybinding + ''); } })(that, id_act, idx); } diff --git a/notebook/static/notebook/less/menubar.less b/notebook/static/notebook/less/menubar.less index 0a7b54f230..b619f08256 100644 --- a/notebook/static/notebook/less/menubar.less +++ b/notebook/static/notebook/less/menubar.less @@ -146,8 +146,14 @@ ul#help_menu li a{ margin-left: 10px; } +.action { + +} + .kb { - float: right; + color: darkgray; + margin-left: 10px; + text-transform: capitalize; } //end submenu From f96a6e852710b3c9118f6d7191becb99865421c0 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Sat, 4 Nov 2017 09:21:16 -0700 Subject: [PATCH 4/8] Humanize keybindings for display --- notebook/static/notebook/js/menubar.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 551cabb5da..15d13e7629 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -7,10 +7,11 @@ define([ 'base/js/dialog', 'base/js/utils', 'base/js/i18n', + 'notebook/js/quickhelp', './celltoolbar', './tour', 'moment', -], function($, IPython, dialog, utils, i18n, celltoolbar, tour, moment) { +], function($, IPython, dialog, utils, i18n, quickhelp, celltoolbar, tour, moment) { "use strict"; var MenuBar = function (selector, options) { @@ -286,12 +287,13 @@ define([ var keybinding = that.keyboard_manager.command_shortcuts.get_action_shortcut(id_act) || that.keyboard_manager.edit_shortcuts.get_action_shortcut(id_act); if (keybinding) { + var shortcut = quickhelp.humanize_sequence(keybinding); var link_element = el.children('a'); var text = link_element.text(); link_element.text(''); link_element.attr('style', 'display: flex; flex-direction: row; justify-content: space-between; align-items: flex-end;'); link_element.append('' + text + ''); - link_element.append('' + keybinding + ''); + link_element.append('' + shortcut + ''); } })(that, id_act, idx); } From 2ef8eb95a124007b2e5652bf6921d1cb258e8fad Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Tue, 7 Nov 2017 13:18:59 -0800 Subject: [PATCH 5/8] Add some missing menu item/action pairs --- notebook/static/notebook/js/menubar.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 15d13e7629..998a696b06 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -235,6 +235,9 @@ define([ '#int_kernel': 'interrupt-kernel', '#cut_cell': 'cut-cell', '#copy_cell': 'copy-cell', + '#paste_cell_above': 'paste-cell-above', + '#paste_cell_below': 'paste-cell-below', + '#paste_cell_replace': 'paste-cell-replace', '#delete_cell': 'delete-cell', '#undelete_cell': 'undo-cell-deletion', '#split_cell': 'split-cell-at-cursor', @@ -266,6 +269,7 @@ define([ '#copy_cell_attachments': 'copy-cell-attachments', '#paste_cell_attachments': 'paste-cell-attachments', '#insert_image': 'insert-image', + '#keyboard_shortcuts' : 'show-keyboard-shortcuts', '#edit_keyboard_shortcuts' : 'edit-command-mode-keyboard-shortcuts', }; @@ -311,9 +315,6 @@ define([ } else { this.element.find('#notebook_tour').addClass("disabled"); } - this.element.find('#keyboard_shortcuts').click(function () { - that.quick_help.show_keyboard_shortcuts(); - }); this.update_restore_checkpoint(null); From dae16d4c569a9ca7ca707b8779aa9105ec791f11 Mon Sep 17 00:00:00 2001 From: Grant Nestor Date: Wed, 15 Nov 2017 13:53:34 -0800 Subject: [PATCH 6/8] Move styles to stylesheet --- notebook/static/notebook/js/menubar.js | 2 +- notebook/static/notebook/less/menubar.less | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/notebook/static/notebook/js/menubar.js b/notebook/static/notebook/js/menubar.js index 998a696b06..aab86f79f5 100644 --- a/notebook/static/notebook/js/menubar.js +++ b/notebook/static/notebook/js/menubar.js @@ -295,7 +295,7 @@ define([ var link_element = el.children('a'); var text = link_element.text(); link_element.text(''); - link_element.attr('style', 'display: flex; flex-direction: row; justify-content: space-between; align-items: flex-end;'); + link_element.addClass('menu-shortcut-container'); link_element.append('' + text + ''); link_element.append('' + shortcut + ''); } diff --git a/notebook/static/notebook/less/menubar.less b/notebook/static/notebook/less/menubar.less index b619f08256..0ceddb0d1d 100644 --- a/notebook/static/notebook/less/menubar.less +++ b/notebook/static/notebook/less/menubar.less @@ -71,6 +71,13 @@ i.menu-icon { .pull-left(); } +ul.dropdown-menu li a.menu-shortcut-container { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: flex-end; +} + ul#help_menu li a{ overflow: hidden; padding-right: 2.2em; From fb53782f4a1eeaf4178bc67bfdd8a866e2ff50d8 Mon Sep 17 00:00:00 2001 From: Jarrad Whitaker Date: Tue, 3 Dec 2019 11:46:11 +1100 Subject: [PATCH 7/8] remove click event add/removal in enable/disable_paste --- notebook/static/notebook/js/notebook.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/notebook/static/notebook/js/notebook.js b/notebook/static/notebook/js/notebook.js index 230fe92c6e..d126fca7ec 100644 --- a/notebook/static/notebook/js/notebook.js +++ b/notebook/static/notebook/js/notebook.js @@ -1619,17 +1619,11 @@ define([ var that = this; if (!this.paste_enabled) { $('#paste_cell_replace').removeClass('disabled') - .on('click', function () {that.keyboard_manager.actions.call( - 'jupyter-notebook:paste-cell-replace');}); - $('#paste_cell_replace > a').attr('aria-disabled', 'false'); + $('#paste_cell_replace > a').attr('aria-disabled', 'false'); $('#paste_cell_above').removeClass('disabled') - .on('click', function () {that.keyboard_manager.actions.call( - 'jupyter-notebook:paste-cell-above');}); - $('#paste_cell_above > a').attr('aria-disabled', 'false'); + $('#paste_cell_above > a').attr('aria-disabled', 'false'); $('#paste_cell_below').removeClass('disabled') - .on('click', function () {that.keyboard_manager.actions.call( - 'jupyter-notebook:paste-cell-below');}); - $('#paste_cell_below > a').attr('aria-disabled', 'false'); + $('#paste_cell_below > a').attr('aria-disabled', 'false'); this.paste_enabled = true; } }; @@ -1639,12 +1633,12 @@ define([ */ Notebook.prototype.disable_paste = function () { if (this.paste_enabled) { - $('#paste_cell_replace').addClass('disabled').off('click'); - $('#paste_cell_replace > a').attr('aria-disabled', 'true'); - $('#paste_cell_above').addClass('disabled').off('click'); - $('#paste_cell_above > a').attr('aria-disabled', 'true'); - $('#paste_cell_below').addClass('disabled').off('click'); - $('#paste_cell_below > a').attr('aria-disabled', 'true'); + $('#paste_cell_replace').addClass('disabled'); + $('#paste_cell_replace > a').attr('aria-disabled', 'true'); + $('#paste_cell_above').addClass('disabled'); + $('#paste_cell_above > a').attr('aria-disabled', 'true'); + $('#paste_cell_below').addClass('disabled'); + $('#paste_cell_below > a').attr('aria-disabled', 'true'); this.paste_enabled = false; } }; From 98f64649f252213d94cd25287a1db53c96a63d9b Mon Sep 17 00:00:00 2001 From: Pierre Monod-Broca Date: Fri, 19 Jun 2020 23:08:40 +0200 Subject: [PATCH 8/8] change the CSS rule to avoid wrapping in the middle of the shortcut text (#2759) --- notebook/static/notebook/less/menubar.less | 3 +++ 1 file changed, 3 insertions(+) diff --git a/notebook/static/notebook/less/menubar.less b/notebook/static/notebook/less/menubar.less index 0ceddb0d1d..1f6acbde75 100644 --- a/notebook/static/notebook/less/menubar.less +++ b/notebook/static/notebook/less/menubar.less @@ -161,6 +161,9 @@ ul#help_menu li a{ color: darkgray; margin-left: 10px; text-transform: capitalize; + kbd { + white-space: nowrap; + } } //end submenu