From a6d2fb253b8a2ff25b1f6ff21963de440dbd0fa5 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 10 Aug 2015 19:08:09 -0700 Subject: [PATCH] humanize shortcut, plus toolbar action --- notebook/static/notebook/js/actions.js | 4 +- notebook/static/notebook/js/commandpalette.js | 49 +++++++++++++------ notebook/static/notebook/js/maintoolbar.js | 3 +- notebook/static/notebook/js/quickhelp.js | 8 ++- notebook/static/notebook/less/notebook.less | 5 ++ 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/notebook/static/notebook/js/actions.js b/notebook/static/notebook/js/actions.js index 6ff98e9b2..5d4901a9f 100644 --- a/notebook/static/notebook/js/actions.js +++ b/notebook/static/notebook/js/actions.js @@ -333,7 +333,9 @@ define(function(require){ } }, 'command-palette': { - help_index : 'aa', + help_index : 'aa', + help: 'open the command palette', + icon: 'fa-search', handler : function(env){ env.notebook.show_command_palette(); } diff --git a/notebook/static/notebook/js/commandpalette.js b/notebook/static/notebook/js/commandpalette.js index 5da51fe85..9f25f022a 100644 --- a/notebook/static/notebook/js/commandpalette.js +++ b/notebook/static/notebook/js/commandpalette.js @@ -4,6 +4,7 @@ define(function(require){ "use strict"; + var QH = require("notebook/js/quickhelp"); var $ = require("jquery"); var dialog = require("base/js/dialog"); var CommandPalette = function(notebook) { @@ -25,6 +26,23 @@ define(function(require){ container.append(field); form.append(container); + + var before_close = function () { + // littel trick to trigger early in onSubmit + // when the action called pop-up a dialog + if(before_close.ok){ + return; + } + if (notebook) { + var cell = notebook.get_selected_cell(); + if (cell) cell.select(); + } + if (notebook.keyboard_manager) { + notebook.keyboard_manager.enable(); + notebook.keyboard_manager.command_mode(); + } + before_close.ok = true; // avoid double call. + } var mod = $('
').addClass('modal').append( $('
').addClass('modal-dialog') @@ -43,17 +61,12 @@ define(function(require){ .modal({show: false, backdrop:true}) .on('shown.bs.modal', function () { input.focus(); + // click on button trigger de-focus on mouse up. + // or somethign like that. + setTimeout(function(){ input.focus()},100); }) - .on("hidden.bs.modal", function () { - if (notebook) { - var cell = notebook.get_selected_cell(); - if (cell) cell.select(); - } - if (notebook.keyboard_manager) { - notebook.keyboard_manager.enable(); - notebook.keyboard_manager.command_mode(); - } - }); + .on("hide.bs.modal", before_close); + notebook.keyboard_manager.disable(); @@ -61,6 +74,7 @@ define(function(require){ var onSubmit = function (node, query, result, resultCount) { console.log(node, query, result, resultCount); if (actions.indexOf(result.key) >= 0) { + before_close(); IPython.notebook.keyboard_manager.actions.call(result.key); } else { console.log("No command " + result.key) @@ -95,9 +109,13 @@ define(function(require){ group = 'built-in'; } src[group] = src[group] || {data:[], display:'display'}; + var short = IPython.keyboard_manager.command_shortcuts.get_shortcut_for_action_name(actions[i]) + || IPython.keyboard_manager.edit_shortcuts.get_shortcut_for_action_name(actions[i]); + if(short){ + short = QH.humanize_shortcut( short) + } src[group].data.push({ display: hum(actions[i]), - shortcut:IPython.keyboard_manager.command_shortcuts.get_shortcut_for_action_name(actions[i]) - || IPython.keyboard_manager.edit_shortcuts.get_shortcut_for_action_name(actions[i]), + shortcut:short, key:actions[i], modesht: mode(actions[i]), group:group, @@ -106,8 +124,8 @@ define(function(require){ }) } input.typeahead({ - emptyTemplate: "No results found for {{query}}", - maxItem: 15, + emptyTemplate: "No results found for
{{query}}
", + maxItem: 1e3, minLength: 0, hint: true, group: ["group", "{{group}} extension"], @@ -120,7 +138,8 @@ define(function(require){ onInit: function () {console.log('this is init') }, onSubmit: onSubmit , onClickAfter: onSubmit - } + }, + debug: false, }) mod.modal('show') diff --git a/notebook/static/notebook/js/maintoolbar.js b/notebook/static/notebook/js/maintoolbar.js index 9be2bf01d..3863e7490 100644 --- a/notebook/static/notebook/js/maintoolbar.js +++ b/notebook/static/notebook/js/maintoolbar.js @@ -55,7 +55,8 @@ define([ ], 'run_int'], [''], - [''] + [''], + [['ipython.command-palette']] ]; this.construct(grps); }; diff --git a/notebook/static/notebook/js/quickhelp.js b/notebook/static/notebook/js/quickhelp.js index 8a46d66bd..377ea3bb4 100644 --- a/notebook/static/notebook/js/quickhelp.js +++ b/notebook/static/notebook/js/quickhelp.js @@ -70,6 +70,7 @@ define([ // these are the standard symbol that are used in MacOS native menus // cf http://apple.stackexchange.com/questions/55727/ // for htmlentities and/or unicode value + 'meta':'⌘', 'cmd':'⌘', 'shift':'⇧', 'alt':'⌥', @@ -98,6 +99,7 @@ define([ var default_humanize_map = { 'shift':'Shift', 'alt':'Alt', + 'meta': 'Alt', 'up':'Up', 'down':'Down', 'left':'Left', @@ -144,7 +146,7 @@ define([ var sh = _.map(shortcut.split('-'), humanize_key ).join(joinchar); return sh; } - + QuickHelp.prototype.show_keyboard_shortcuts = function () { /** @@ -292,5 +294,7 @@ define([ return div; }; - return {'QuickHelp': QuickHelp}; + return {'QuickHelp': QuickHelp, + humanize_shortcut: humanize_shortcut + }; }); diff --git a/notebook/static/notebook/less/notebook.less b/notebook/static/notebook/less/notebook.less index b3a3749be..fda18b1d1 100644 --- a/notebook/static/notebook/less/notebook.less +++ b/notebook/static/notebook/less/notebook.less @@ -135,3 +135,8 @@ ul.typeahead-list i{ width: 18px; border: thin solid transparent; } + +ul.typeahead-list { + max-height: 80vh; + overflow:auto; +}