mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
rework keyboard management to avoit completer and up/down bugs
This commit is contained in:
parent
5b355936df
commit
804d89351b
@ -198,9 +198,22 @@ define([
|
||||
Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
|
||||
var shortcuts = this.keyboard_manager.edit_shortcuts;
|
||||
|
||||
var cur = editor.getCursor();
|
||||
if((cur.line !== 0 || cur.ch !==0) && event.keyCode === 38){
|
||||
event._ipkmIgnore = true;
|
||||
}
|
||||
var nLastLine = editor.lastLine()
|
||||
if( ( event.keyCode === 40)
|
||||
&& (( cur.line !== nLastLine)
|
||||
|| ( cur.ch !== editor.getLineHandle(nLastLine).text.length))
|
||||
){
|
||||
event._ipkmIgnore = true;
|
||||
}
|
||||
// if this is an edit_shortcuts shortcut, the global keyboard/shortcut
|
||||
// manager will handle it
|
||||
if (shortcuts.handles(event)) { return true; }
|
||||
if (shortcuts.handles(event)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
@ -291,7 +304,6 @@ define([
|
||||
* @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise
|
||||
*/
|
||||
Cell.prototype.handle_keyevent = function (editor, event) {
|
||||
|
||||
if (this.mode === 'command') {
|
||||
return true;
|
||||
} else if (this.mode === 'edit') {
|
||||
|
@ -114,7 +114,7 @@ define([
|
||||
* @param name {String} name to use to refer to the callback. It is advised to use a prefix with the name
|
||||
* for easier sorting and avoid collision
|
||||
* @param callback {function(div, cell)} callback that will be called to generate the ui element
|
||||
* @param [cell_types] {List of String|undefined} optional list of cell types. If present the UI element
|
||||
* @param [cell_types] {List_of_String|undefined} optional list of cell types. If present the UI element
|
||||
* will be added only to cells of types in the list.
|
||||
*
|
||||
*
|
||||
@ -163,7 +163,7 @@ define([
|
||||
* @method register_preset
|
||||
* @param name {String} name to use to refer to the preset. It is advised to use a prefix with the name
|
||||
* for easier sorting and avoid collision
|
||||
* @param preset_list {List of String} reverse order of the button in the toolbar. Each String of the list
|
||||
* @param preset_list {List_of_String} reverse order of the button in the toolbar. Each String of the list
|
||||
* should correspond to a name of a registerd callback.
|
||||
*
|
||||
* @private
|
||||
@ -288,8 +288,6 @@ define([
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
CellToolbar.utils = {};
|
||||
|
||||
|
||||
@ -385,7 +383,7 @@ define([
|
||||
* @method utils.select_ui_generator
|
||||
* @static
|
||||
*
|
||||
* @param list_list {list of sublist} List of sublist of metadata value and name in the dropdown list.
|
||||
* @param list_list {list_of_sublist} List of sublist of metadata value and name in the dropdown list.
|
||||
* subslit shoud contain 2 element each, first a string that woul be displayed in the dropdown list,
|
||||
* and second the corresponding value to be passed to setter/return by getter. the corresponding value
|
||||
* should not be "undefined" or behavior can be unexpected.
|
||||
|
@ -83,11 +83,7 @@ define([
|
||||
this.completer = null;
|
||||
|
||||
|
||||
var cm_overwrite_options = {
|
||||
onKeyEvent: $.proxy(this.handle_keyevent,this)
|
||||
};
|
||||
|
||||
var config = utils.mergeopt(CodeCell, this.config, {cm_config: cm_overwrite_options});
|
||||
var config = utils.mergeopt(CodeCell, this.config);
|
||||
Cell.apply(this,[{
|
||||
config: config,
|
||||
keyboard_manager: options.keyboard_manager,
|
||||
@ -144,7 +140,7 @@ define([
|
||||
inner_cell.append(this.celltoolbar.element);
|
||||
var input_area = $('<div/>').addClass('input_area');
|
||||
this.code_mirror = new CodeMirror(input_area.get(0), this.cm_config);
|
||||
this.code_mirror.on('keydown', $.proxy(this.handle_codemirror_keyevent,this))
|
||||
this.code_mirror.on('keydown', $.proxy(this.handle_keyevent,this))
|
||||
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
|
||||
inner_cell.append(input_area);
|
||||
input.append(prompt).append(inner_cell);
|
||||
|
@ -318,11 +318,13 @@ define([
|
||||
// Enter
|
||||
if (code == keycodes.enter) {
|
||||
event.codemirrorIgnore = true;
|
||||
event._ipkmIgnore = true;
|
||||
event.preventDefault();
|
||||
this.pick();
|
||||
// Escape or backspace
|
||||
} else if (code == keycodes.esc || code == keycodes.backspace) {
|
||||
event.codemirrorIgnore = true;
|
||||
event._ipkmIgnore = true;
|
||||
event.preventDefault();
|
||||
this.close();
|
||||
} else if (code == keycodes.tab) {
|
||||
@ -343,6 +345,7 @@ define([
|
||||
// need to do that to be able to move the arrow
|
||||
// when on the first or last line ofo a code cell
|
||||
event.codemirrorIgnore = true;
|
||||
event._ipkmIgnore = true;
|
||||
event.preventDefault();
|
||||
|
||||
var options = this.sel.find('option');
|
||||
@ -356,7 +359,7 @@ define([
|
||||
index = Math.min(Math.max(index, 0), options.length-1);
|
||||
this.sel[0].selectedIndex = index;
|
||||
} else if (code == keycodes.pageup || code == keycodes.pagedown) {
|
||||
CodeMirror.e_stop(event);
|
||||
event._ipkmIgnore = true;
|
||||
|
||||
var options = this.sel.find('option');
|
||||
var index = this.sel[0].selectedIndex;
|
||||
|
@ -227,6 +227,9 @@ define([
|
||||
help : 'select previous cell',
|
||||
help_index : 'da',
|
||||
handler : function (event) {
|
||||
if(event.codemirrorIgnore===true){
|
||||
return false;
|
||||
}
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== 0 && index !== null) {
|
||||
that.notebook.select_prev();
|
||||
@ -239,6 +242,9 @@ define([
|
||||
help : 'select next cell',
|
||||
help_index : 'db',
|
||||
handler : function (event) {
|
||||
if(event.codemirrorIgnore===true){
|
||||
return false;
|
||||
}
|
||||
var index = that.notebook.get_selected_index();
|
||||
if (index !== (that.notebook.ncells()-1) && index !== null) {
|
||||
that.notebook.select_next();
|
||||
@ -508,6 +514,9 @@ define([
|
||||
KeyboardManager.prototype.bind_events = function () {
|
||||
var that = this;
|
||||
$(document).keydown(function (event) {
|
||||
if(event._ipkmIgnore==true||event.originalEvent._ipkmIgnore==true){
|
||||
return false;
|
||||
}
|
||||
return that.handle_keydown(event);
|
||||
});
|
||||
};
|
||||
|
@ -893,7 +893,7 @@ define([
|
||||
* Insert an element at given cell index.
|
||||
*
|
||||
* @method _insert_element_at_index
|
||||
* @param element {dom element} a cell element
|
||||
* @param element {dom_element} a cell element
|
||||
* @param [index] {int} a valid index where to inser cell
|
||||
* @private
|
||||
*
|
||||
|
@ -11,7 +11,7 @@ define([
|
||||
* A generic toolbar on which one can add button
|
||||
* @class ToolBar
|
||||
* @constructor
|
||||
* @param {Dom object} selector
|
||||
* @param {Dom_object} selector
|
||||
*/
|
||||
var ToolBar = function (selector, layout_manager) {
|
||||
this.selector = selector;
|
||||
|
Loading…
Reference in New Issue
Block a user