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'],
['