/usr/lib/python2.7/dist-packages/notebook/static/notebook/js/commandpalette.js is in python-notebook 5.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | // Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
define([
'jquery',
'typeahead',
'base/js/i18n',
'notebook/js/quickhelp'
],function($, typeahead, i18n, QH){
"use strict";
/**
* Humanize the action name to be consumed by user.
* internaly the actions anem are of the form
* <namespace>:<description-with-dashes>
* we drop <namesapce> and replace dashes for space.
*/
var humanize_action_id = function(str) {
return str.split(':')[1].replace(/-/g, ' ').replace(/_/g, '-');
};
/**
* given an action id return 'command-shortcut', 'edit-shortcut' or 'no-shortcut'
* for the action. This allows us to tag UI in order to visually distinguish
* wether an action have a keybinding or not.
**/
var get_mode_for_action_id = function(name, notebook) {
var shortcut = notebook.keyboard_manager.command_shortcuts.get_action_shortcut(name);
if (shortcut) {
return 'command-shortcut';
}
shortcut = notebook.keyboard_manager.edit_shortcuts.get_action_shortcut(name);
if (shortcut) {
return 'edit-shortcut';
}
return 'no-shortcut';
};
var CommandPalette = function(notebook) {
if(!notebook){
throw new Error("CommandPalette takes a notebook non-null mandatory arguement");
}
// typeahead lib need a specific layout with specific class names.
// the following just does that
var form = $('<form/>');
var container = $('<div/>').addClass('typeahead-container');
var field = $('<div/>').addClass('typeahead-field');
var input = $('<input/>').attr('type', 'search');
field
.append(
$('<span>').addClass('typeahead-query').append(
input
)
)
.append(
$('<span/>').addClass('typeahead-button').append(
$('<button/>').attr('type', 'submit').append(
$('<span/>').addClass('typeahead-search-icon')
)
)
);
container.append(field);
form.append(container);
var mod = $('<div/>').addClass('modal cmd-palette').append(
$('<div/>').addClass('modal-dialog')
.append(
$('<div/>').addClass('modal-content').append(
$('<div/>').addClass('modal-body')
.append(
form
)
)
)
)
// end setting up right layout
.modal({show: false, backdrop:true})
.on('shown.bs.modal', function () {
// click on button trigger de-focus on mouse up.
// or somethign like that.
setTimeout(function(){input.focus();}, 100);
});
notebook.keyboard_manager.disable();
var before_close = function() {
// little trick to trigger early in onsubmit
// when the action called pop-up a dialog
// insure this function is only called once
if (before_close.ok) {
return;
}
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.
};
mod.on("hide.bs.modal", before_close);
// will be trigger when user select action
var onSubmit = function(node, query, result, resultCount) {
if (actions.indexOf(result.key) >= 0) {
before_close();
notebook.keyboard_manager.actions.call(result.key);
} else {
console.warning("No command " + result.key);
}
mod.modal('hide');
};
/* Whenever a result is rendered, if there is only one resulting
* element then automatically select that element.
*/
var onResult = function(node, query, result, resultCount) {
if (resultCount == 1) {
requestAnimationFrame(function() {
$('.typeahead-list > li:nth-child(2)').addClass('active');
});
}
};
// generate structure needed for typeahead layout and ability to search
var src = {};
var actions = Object.keys(notebook.keyboard_manager.actions._actions);
for (var i = 0; i < actions.length; i++) {
var action_id = actions[i];
var action = notebook.keyboard_manager.actions.get(action_id);
var group = action_id.split(':')[0];
src[group] = src[group] || {
data: [],
display: 'display'
};
var short = notebook.keyboard_manager.command_shortcuts.get_action_shortcut(action_id) ||
notebook.keyboard_manager.edit_shortcuts.get_action_shortcut(action_id);
if (short) {
short = QH.humanize_sequence(short);
}
var display_text;
if (action.cmd) {
display_text = i18n.msg._(action.cmd);
} else {
display_text = humanize_action_id(action_id);
}
src[group].data.push({
display: display_text,
shortcut: short,
mode_shortcut: get_mode_for_action_id(action_id, notebook),
group: group,
icon: action.icon,
help: i18n.msg._(action.help),
key: action_id,
});
}
// now src is the right structure for typeahead
input.typeahead({
emptyTemplate: function(query) {
return $('<div>').text("No results found for ").append(
$('<code>').text(query)
);
},
maxItem: 1e3,
minLength: 0,
hint: true,
group: ["group", "{{group}} command group"],
searchOnFocus: true,
mustSelectItem: true,
template: '<i class="fa fa-icon {{icon}}"></i>{{display}} <div title={{key}} class="pull-right {{mode_shortcut}}">{{shortcut}}</div>',
order: "asc",
source: src,
callback: {
onSubmit: onSubmit,
onClickAfter: onSubmit,
onResult: onResult
},
debug: false,
});
mod.modal('show');
};
return {'CommandPalette': CommandPalette};
});
|