From 2c9ff376a272a187849ef29178f7b67bbe3329bb Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Fri, 7 Mar 2014 17:22:37 -0800 Subject: [PATCH] added new use_shortcut method to shortcuts this way, you can ask if a particular event will be handled by the shortcuts system. This takes away the need to special-case many different possible keys which should be ignored by codemirror by ignoring them en masse. --- IPython/html/static/base/js/keyboard.js | 6 ++++++ IPython/html/static/notebook/js/cell.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/IPython/html/static/base/js/keyboard.js b/IPython/html/static/base/js/keyboard.js index 20e38ba22..c009d609b 100644 --- a/IPython/html/static/base/js/keyboard.js +++ b/IPython/html/static/base/js/keyboard.js @@ -237,6 +237,12 @@ IPython.keyboard = (function (IPython) { return true; } + ShortcutManager.prototype.use_shortcut = function (event) { + var shortcut = event_to_shortcut(event); + var data = this._shortcuts[shortcut]; + return !( data === undefined ) + } + return { keycodes : keycodes, inv_keycodes : inv_keycodes, diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 994f6435d..469e6a205 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -169,7 +169,11 @@ var IPython = (function (IPython) { */ Cell.prototype.handle_codemirror_keyevent = function (editor, event) { var that = this; + var shortcuts = IPython.keyboard_manager.edit_shortcuts; + // if this is an edit_shortcuts shortcut, we've already handled it. + if (shortcuts.use_shortcut(event)) { return true; } + if (event.keyCode === keycodes.enter && (event.shiftKey || event.ctrlKey || event.altKey)) { // Always ignore shift-enter in CodeMirror as we handle it. return true;