keyboardmanager.js
562 lines
| 17.6 KiB
| application/javascript
|
JavascriptLexer
Brian E. Granger
|
r14020 | //---------------------------------------------------------------------------- | ||
// Copyright (C) 2011 The IPython Development Team | ||||
// | ||||
// Distributed under the terms of the BSD License. The full license is in | ||||
// the file COPYING, distributed as part of this software. | ||||
//---------------------------------------------------------------------------- | ||||
//============================================================================ | ||||
// Keyboard management | ||||
//============================================================================ | ||||
var IPython = (function (IPython) { | ||||
"use strict"; | ||||
Brian E. Granger
|
r14036 | var browser = IPython.utils.browser[0]; | ||
Brian E. Granger
|
r14816 | var platform = IPython.utils.platform; | ||
Brian E. Granger
|
r14036 | |||
// Default keyboard shortcuts | ||||
var default_common_shortcuts = { | ||||
'shift' : { | ||||
help : '', | ||||
Brian E. Granger
|
r14093 | help_index : '', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
// ignore shift keydown | ||||
return true; | ||||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'shift-enter' : { | ||
Brian E. Granger
|
r14946 | help : 'run cell, select below', | ||
Brian E. Granger
|
r14093 | help_index : 'ba', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14945 | IPython.notebook.execute_cell_and_select_below(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'ctrl-enter' : { | ||
Brian E. Granger
|
r14946 | help : 'run cell', | ||
Brian E. Granger
|
r14093 | help_index : 'bb', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14945 | IPython.notebook.execute_cell(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'alt-enter' : { | ||
Brian E. Granger
|
r14093 | help : 'run cell, insert below', | ||
help_index : 'bc', | ||||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14093 | IPython.notebook.execute_cell_and_insert_below(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
} | ||||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14036 | |||
Brian E. Granger
|
r14816 | if (platform === 'MacOS') { | ||
Paul Ivanov
|
r15890 | default_common_shortcuts['cmd-s'] = | ||
Brian E. Granger
|
r14816 | { | ||
help : 'save notebook', | ||||
help_index : 'fb', | ||||
handler : function (event) { | ||||
IPython.notebook.save_checkpoint(); | ||||
event.preventDefault(); | ||||
return false; | ||||
} | ||||
}; | ||||
} else { | ||||
Paul Ivanov
|
r15873 | default_common_shortcuts['ctrl-s'] = | ||
Brian E. Granger
|
r14816 | { | ||
help : 'save notebook', | ||||
help_index : 'fb', | ||||
handler : function (event) { | ||||
IPython.notebook.save_checkpoint(); | ||||
event.preventDefault(); | ||||
return false; | ||||
} | ||||
}; | ||||
} | ||||
Brian E. Granger
|
r14036 | // Edit mode defaults | ||
var default_edit_shortcuts = { | ||||
'esc' : { | ||||
help : 'command mode', | ||||
Brian E. Granger
|
r14093 | help_index : 'aa', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.command_mode(); | ||||
return false; | ||||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'ctrl-m' : { | ||
Brian E. Granger
|
r14036 | help : 'command mode', | ||
Brian E. Granger
|
r14093 | help_index : 'ab', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.command_mode(); | ||||
return false; | ||||
} | ||||
}, | ||||
'up' : { | ||||
Brian E. Granger
|
r14099 | help : '', | ||
help_index : '', | ||||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Jonathan Frederic
|
r15593 | var index = IPython.notebook.get_selected_index(); | ||
Paul Ivanov
|
r15837 | var cell = IPython.notebook.get_cell(index); | ||
if (cell && cell.at_top() && index !== 0) { | ||||
event.preventDefault(); | ||||
IPython.notebook.command_mode(); | ||||
IPython.notebook.select_prev(); | ||||
IPython.notebook.edit_mode(); | ||||
var cm = IPython.notebook.get_selected_cell().code_mirror; | ||||
cm.setCursor(cm.lastLine(), 0); | ||||
return false; | ||||
} else if (cell) { | ||||
var cm = cell.code_mirror; | ||||
Paul Ivanov
|
r16522 | cm.execCommand('goLineUp'); | ||
Paul Ivanov
|
r15837 | return false; | ||
Jonathan Frederic
|
r15491 | } | ||
Brian E. Granger
|
r14036 | } | ||
}, | ||||
'down' : { | ||||
Brian E. Granger
|
r14099 | help : '', | ||
help_index : '', | ||||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Jonathan Frederic
|
r15594 | var index = IPython.notebook.get_selected_index(); | ||
Paul Ivanov
|
r15837 | var cell = IPython.notebook.get_cell(index); | ||
if (cell.at_bottom() && index !== (IPython.notebook.ncells()-1)) { | ||||
event.preventDefault(); | ||||
IPython.notebook.command_mode(); | ||||
IPython.notebook.select_next(); | ||||
IPython.notebook.edit_mode(); | ||||
var cm = IPython.notebook.get_selected_cell().code_mirror; | ||||
cm.setCursor(0, 0); | ||||
return false; | ||||
} else { | ||||
var cm = cell.code_mirror; | ||||
Paul Ivanov
|
r16522 | cm.execCommand('goLineDown'); | ||
Paul Ivanov
|
r15837 | return false; | ||
Jonathan Frederic
|
r15491 | } | ||
Brian E. Granger
|
r14036 | } | ||
}, | ||||
MinRK
|
r15898 | 'ctrl-shift--' : { | ||
Brian E. Granger
|
r14057 | help : 'split cell', | ||
Brian E. Granger
|
r14093 | help_index : 'ea', | ||
Brian E. Granger
|
r14057 | handler : function (event) { | ||
IPython.notebook.split_cell(); | ||||
return false; | ||||
} | ||||
}, | ||||
MinRK
|
r15898 | 'ctrl-shift-subtract' : { | ||
Brian E. Granger
|
r14093 | help : '', | ||
help_index : 'eb', | ||||
Brian E. Granger
|
r14076 | handler : function (event) { | ||
IPython.notebook.split_cell(); | ||||
return false; | ||||
} | ||||
}, | ||||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14816 | |||
Brian E. Granger
|
r14036 | // Command mode defaults | ||
var default_command_shortcuts = { | ||||
'enter' : { | ||||
help : 'edit mode', | ||||
Brian E. Granger
|
r14093 | help_index : 'aa', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Jonathan Frederic
|
r15541 | IPython.notebook.edit_mode(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'up' : { | ||||
help : 'select previous cell', | ||||
Brian E. Granger
|
r14093 | help_index : 'da', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
var index = IPython.notebook.get_selected_index(); | ||||
if (index !== 0 && index !== null) { | ||||
IPython.notebook.select_prev(); | ||||
Jonathan Frederic
|
r15539 | IPython.notebook.focus_cell(); | ||
Jonathan Frederic
|
r15491 | } | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'down' : { | ||||
help : 'select next cell', | ||||
Brian E. Granger
|
r14093 | help_index : 'db', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
var index = IPython.notebook.get_selected_index(); | ||||
if (index !== (IPython.notebook.ncells()-1) && index !== null) { | ||||
IPython.notebook.select_next(); | ||||
Jonathan Frederic
|
r15539 | IPython.notebook.focus_cell(); | ||
Jonathan Frederic
|
r15491 | } | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
Brian E. Granger
|
r14038 | 'k' : { | ||
help : 'select previous cell', | ||||
Brian E. Granger
|
r14093 | help_index : 'dc', | ||
Brian E. Granger
|
r14038 | handler : function (event) { | ||
var index = IPython.notebook.get_selected_index(); | ||||
if (index !== 0 && index !== null) { | ||||
IPython.notebook.select_prev(); | ||||
Jonathan Frederic
|
r15539 | IPython.notebook.focus_cell(); | ||
Jonathan Frederic
|
r15491 | } | ||
Brian E. Granger
|
r14038 | return false; | ||
} | ||||
}, | ||||
'j' : { | ||||
help : 'select next cell', | ||||
Brian E. Granger
|
r14093 | help_index : 'dd', | ||
Brian E. Granger
|
r14038 | handler : function (event) { | ||
var index = IPython.notebook.get_selected_index(); | ||||
if (index !== (IPython.notebook.ncells()-1) && index !== null) { | ||||
IPython.notebook.select_next(); | ||||
Jonathan Frederic
|
r15539 | IPython.notebook.focus_cell(); | ||
Jonathan Frederic
|
r15491 | } | ||
Brian E. Granger
|
r14038 | return false; | ||
} | ||||
}, | ||||
Brian E. Granger
|
r14036 | 'x' : { | ||
help : 'cut cell', | ||||
Brian E. Granger
|
r14093 | help_index : 'ee', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14037 | IPython.notebook.cut_cell(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'c' : { | ||||
help : 'copy cell', | ||||
Brian E. Granger
|
r14093 | help_index : 'ef', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14037 | IPython.notebook.copy_cell(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'shift-v' : { | ||
Brian E. Granger
|
r14810 | help : 'paste cell above', | ||
help_index : 'eg', | ||||
handler : function (event) { | ||||
IPython.notebook.paste_cell_above(); | ||||
return false; | ||||
} | ||||
}, | ||||
Brian E. Granger
|
r14036 | 'v' : { | ||
help : 'paste cell below', | ||||
Brian E. Granger
|
r14810 | help_index : 'eh', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14037 | IPython.notebook.paste_cell_below(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'd' : { | ||||
help : 'delete cell (press twice)', | ||||
Brian E. Granger
|
r14810 | help_index : 'ej', | ||
count: 2, | ||||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Brian E. Granger
|
r14810 | IPython.notebook.delete_cell(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'a' : { | ||||
help : 'insert cell above', | ||||
Brian E. Granger
|
r14093 | help_index : 'ec', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Paul Ivanov
|
r16778 | IPython.notebook.insert_cell_above(); | ||
Brian E. Granger
|
r14036 | IPython.notebook.select_prev(); | ||
Brian E. Granger
|
r14075 | IPython.notebook.focus_cell(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'b' : { | ||||
help : 'insert cell below', | ||||
Brian E. Granger
|
r14093 | help_index : 'ed', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
Paul Ivanov
|
r16778 | IPython.notebook.insert_cell_below(); | ||
Brian E. Granger
|
r14036 | IPython.notebook.select_next(); | ||
Brian E. Granger
|
r14075 | IPython.notebook.focus_cell(); | ||
Brian E. Granger
|
r14036 | return false; | ||
} | ||||
}, | ||||
'y' : { | ||||
help : 'to code', | ||||
Brian E. Granger
|
r14093 | help_index : 'ca', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_code(); | ||||
return false; | ||||
} | ||||
}, | ||||
'm' : { | ||||
help : 'to markdown', | ||||
Brian E. Granger
|
r14093 | help_index : 'cb', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_markdown(); | ||||
return false; | ||||
} | ||||
}, | ||||
Brian E. Granger
|
r14810 | 'r' : { | ||
Brian E. Granger
|
r14036 | help : 'to raw', | ||
Brian E. Granger
|
r14093 | help_index : 'cc', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_raw(); | ||||
return false; | ||||
} | ||||
}, | ||||
'1' : { | ||||
help : 'to heading 1', | ||||
Brian E. Granger
|
r14093 | help_index : 'cd', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_heading(undefined, 1); | ||||
return false; | ||||
} | ||||
}, | ||||
'2' : { | ||||
help : 'to heading 2', | ||||
Brian E. Granger
|
r14093 | help_index : 'ce', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_heading(undefined, 2); | ||||
return false; | ||||
} | ||||
}, | ||||
'3' : { | ||||
help : 'to heading 3', | ||||
Brian E. Granger
|
r14093 | help_index : 'cf', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_heading(undefined, 3); | ||||
return false; | ||||
} | ||||
}, | ||||
'4' : { | ||||
help : 'to heading 4', | ||||
Brian E. Granger
|
r14093 | help_index : 'cg', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_heading(undefined, 4); | ||||
return false; | ||||
} | ||||
}, | ||||
'5' : { | ||||
help : 'to heading 5', | ||||
Brian E. Granger
|
r14093 | help_index : 'ch', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_heading(undefined, 5); | ||||
return false; | ||||
} | ||||
}, | ||||
'6' : { | ||||
help : 'to heading 6', | ||||
Brian E. Granger
|
r14093 | help_index : 'ci', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.to_heading(undefined, 6); | ||||
return false; | ||||
} | ||||
}, | ||||
'o' : { | ||||
help : 'toggle output', | ||||
Brian E. Granger
|
r14093 | help_index : 'gb', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.toggle_output(); | ||||
return false; | ||||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'shift-o' : { | ||
Brian E. Granger
|
r14871 | help : 'toggle output scrolling', | ||
Brian E. Granger
|
r14093 | help_index : 'gc', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.toggle_output_scroll(); | ||||
return false; | ||||
} | ||||
}, | ||||
's' : { | ||||
help : 'save notebook', | ||||
Brian E. Granger
|
r14093 | help_index : 'fa', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.save_checkpoint(); | ||||
return false; | ||||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'ctrl-j' : { | ||
Brian E. Granger
|
r14036 | help : 'move cell down', | ||
Brian E. Granger
|
r14093 | help_index : 'eb', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.move_cell_down(); | ||||
return false; | ||||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'ctrl-k' : { | ||
Brian E. Granger
|
r14036 | help : 'move cell up', | ||
Brian E. Granger
|
r14093 | help_index : 'ea', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.move_cell_up(); | ||||
return false; | ||||
} | ||||
}, | ||||
'l' : { | ||||
help : 'toggle line numbers', | ||||
Brian E. Granger
|
r14093 | help_index : 'ga', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.cell_toggle_line_numbers(); | ||||
return false; | ||||
} | ||||
}, | ||||
'i' : { | ||||
Brian E. Granger
|
r14810 | help : 'interrupt kernel (press twice)', | ||
Brian E. Granger
|
r14093 | help_index : 'ha', | ||
Brian E. Granger
|
r14810 | count: 2, | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.kernel.interrupt(); | ||||
return false; | ||||
} | ||||
}, | ||||
Brian E. Granger
|
r14810 | '0' : { | ||
help : 'restart kernel (press twice)', | ||||
Brian E. Granger
|
r14093 | help_index : 'hb', | ||
Brian E. Granger
|
r14810 | count: 2, | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.restart_kernel(); | ||||
return false; | ||||
} | ||||
}, | ||||
'h' : { | ||||
help : 'keyboard shortcuts', | ||||
Brian E. Granger
|
r15194 | help_index : 'ge', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.quick_help.show_keyboard_shortcuts(); | ||||
return false; | ||||
} | ||||
}, | ||||
'z' : { | ||||
help : 'undo last delete', | ||||
Brian E. Granger
|
r14810 | help_index : 'ei', | ||
Brian E. Granger
|
r14036 | handler : function (event) { | ||
IPython.notebook.undelete_cell(); | ||||
return false; | ||||
} | ||||
}, | ||||
Paul Ivanov
|
r15873 | 'shift-m' : { | ||
Brian E. Granger
|
r14816 | help : 'merge cell below', | ||
help_index : 'ek', | ||||
handler : function (event) { | ||||
IPython.notebook.merge_cell_below(); | ||||
return false; | ||||
} | ||||
}, | ||||
Brian E. Granger
|
r15194 | 'q' : { | ||
Brian E. Granger
|
r15195 | help : 'close pager', | ||
Brian E. Granger
|
r15194 | help_index : 'gd', | ||
handler : function (event) { | ||||
Brian E. Granger
|
r15195 | IPython.pager.collapse(); | ||
Brian E. Granger
|
r15194 | return false; | ||
} | ||||
}, | ||||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14036 | |||
Brian E. Granger
|
r15615 | // Main keyboard manager for the notebook | ||
Brian E. Granger
|
r14036 | |||
Brian E. Granger
|
r15615 | var ShortcutManager = IPython.keyboard.ShortcutManager; | ||
var keycodes = IPython.keyboard.keycodes; | ||||
Brian E. Granger
|
r14036 | |||
Brian E. Granger
|
r14020 | var KeyboardManager = function () { | ||
Brian E. Granger
|
r14021 | this.mode = 'command'; | ||
Brian E. Granger
|
r14023 | this.enabled = true; | ||
Brian E. Granger
|
r14020 | this.bind_events(); | ||
Brian E. Granger
|
r14036 | this.command_shortcuts = new ShortcutManager(); | ||
this.command_shortcuts.add_shortcuts(default_common_shortcuts); | ||||
this.command_shortcuts.add_shortcuts(default_command_shortcuts); | ||||
this.edit_shortcuts = new ShortcutManager(); | ||||
this.edit_shortcuts.add_shortcuts(default_common_shortcuts); | ||||
this.edit_shortcuts.add_shortcuts(default_edit_shortcuts); | ||||
Brian E. Granger
|
r14020 | }; | ||
KeyboardManager.prototype.bind_events = function () { | ||||
var that = this; | ||||
$(document).keydown(function (event) { | ||||
return that.handle_keydown(event); | ||||
}); | ||||
}; | ||||
KeyboardManager.prototype.handle_keydown = function (event) { | ||||
var notebook = IPython.notebook; | ||||
Brian E. Granger
|
r14089 | |||
Jonathan Frederic
|
r15491 | if (event.which === keycodes.esc) { | ||
Brian E. Granger
|
r14020 | // Intercept escape at highest level to avoid closing | ||
// websocket connection with firefox | ||||
event.preventDefault(); | ||||
} | ||||
Brian E. Granger
|
r14023 | if (!this.enabled) { | ||
Jonathan Frederic
|
r15491 | if (event.which === keycodes.esc) { | ||
Brian E. Granger
|
r14036 | // ESC | ||
notebook.command_mode(); | ||||
return false; | ||||
} | ||||
Brian E. Granger
|
r14023 | return true; | ||
Brian E. Granger
|
r14020 | } | ||
if (this.mode === 'edit') { | ||||
Brian E. Granger
|
r14036 | return this.edit_shortcuts.call_handler(event); | ||
} else if (this.mode === 'command') { | ||||
return this.command_shortcuts.call_handler(event); | ||||
Brian E. Granger
|
r14020 | } | ||
return true; | ||||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14020 | |||
KeyboardManager.prototype.edit_mode = function () { | ||||
this.last_mode = this.mode; | ||||
this.mode = 'edit'; | ||||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14020 | |||
KeyboardManager.prototype.command_mode = function () { | ||||
this.last_mode = this.mode; | ||||
this.mode = 'command'; | ||||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14020 | |||
Brian E. Granger
|
r14024 | KeyboardManager.prototype.enable = function () { | ||
Brian E. Granger
|
r14030 | this.enabled = true; | ||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14024 | |||
KeyboardManager.prototype.disable = function () { | ||||
Brian E. Granger
|
r14030 | this.enabled = false; | ||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14024 | |||
Brian E. Granger
|
r14036 | KeyboardManager.prototype.register_events = function (e) { | ||
var that = this; | ||||
Jonathan Frederic
|
r15496 | var handle_focus = function () { | ||
Brian E. Granger
|
r14036 | that.disable(); | ||
Jonathan Frederic
|
r15496 | }; | ||
var handle_blur = function () { | ||||
Brian E. Granger
|
r14036 | that.enable(); | ||
Jonathan Frederic
|
r15496 | }; | ||
e.on('focusin', handle_focus); | ||||
e.on('focusout', handle_blur); | ||||
Jonathan Frederic
|
r15507 | // TODO: Very strange. The focusout event does not seem fire for the | ||
Jonathan Frederic
|
r15539 | // bootstrap textboxes on FF25&26... This works around that by | ||
// registering focus and blur events recursively on all inputs within | ||||
// registered element. | ||||
Jonathan Frederic
|
r15507 | e.find('input').blur(handle_blur); | ||
e.on('DOMNodeInserted', function (event) { | ||||
var target = $(event.target); | ||||
if (target.is('input')) { | ||||
target.blur(handle_blur); | ||||
} else { | ||||
target.find('input').blur(handle_blur); | ||||
} | ||||
}); | ||||
Brian E. Granger
|
r14046 | // There are times (raw_input) where we remove the element from the DOM before | ||
// focusout is called. In this case we bind to the remove event of jQueryUI, | ||||
MinRK
|
r15328 | // which gets triggered upon removal, iff it is focused at the time. | ||
Jonathan Frederic
|
r15539 | // is_focused must be used to check for the case where an element within | ||
// the element being removed is focused. | ||||
Brian E. Granger
|
r14046 | e.on('remove', function () { | ||
Jonathan Frederic
|
r15494 | if (IPython.utils.is_focused(e[0])) { | ||
MinRK
|
r15328 | that.enable(); | ||
} | ||||
Brian E. Granger
|
r14046 | }); | ||
Jonathan Frederic
|
r15491 | }; | ||
Brian E. Granger
|
r14036 | |||
Brian E. Granger
|
r14024 | |||
Brian E. Granger
|
r14036 | IPython.default_common_shortcuts = default_common_shortcuts; | ||
IPython.default_edit_shortcuts = default_edit_shortcuts; | ||||
IPython.default_command_shortcuts = default_command_shortcuts; | ||||
Brian E. Granger
|
r14020 | IPython.KeyboardManager = KeyboardManager; | ||
return IPython; | ||||
}(IPython)); | ||||