From a1ee7385c4fcab2c879bbb501aca7b85691e2d19 2014-03-08 01:48:34 From: Paul Ivanov Date: 2014-03-08 01:48:34 Subject: [PATCH] DRY: factor out common handle_keyevent method This method was identical in both CodeCell and TextCell --- diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index 67f4eb4..dd33ef9 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -230,6 +230,26 @@ var IPython = (function (IPython) { }; /** + * Either delegates keyboard shortcut handling to either IPython keyboard + * manager when in command mode, or CodeMirror when in edit mode + * + * @method handle_keyevent + * @param {CodeMirror} editor - The codemirror instance bound to the cell + * @param {event} event - + * @return {Boolean} `true` if CodeMirror should ignore the event, `false` Otherwise + */ + CodeCell.prototype.handle_keyevent = function (editor, event) { + + // console.log('CM', this.mode, event.which, event.type) + + if (this.mode === 'command') { + return true; + } else if (this.mode === 'edit') { + return this.handle_codemirror_keyevent(editor, event); + } + }; + + /** * @method at_top * @return {Boolean} */ diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index 44541ec..1241016 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -171,16 +171,6 @@ var IPython = (function (IPython) { ); }; - CodeCell.prototype.handle_keyevent = function (editor, event) { - - // console.log('CM', this.mode, event.which, event.type) - - if (this.mode === 'command') { - return true; - } else if (this.mode === 'edit') { - return this.handle_codemirror_keyevent(editor, event); - } - }; /** * This method gets called in CodeMirror's onKeyDown/onKeyPress diff --git a/IPython/html/static/notebook/js/textcell.js b/IPython/html/static/notebook/js/textcell.js index db69d2d..c60dc6c 100644 --- a/IPython/html/static/notebook/js/textcell.js +++ b/IPython/html/static/notebook/js/textcell.js @@ -113,22 +113,11 @@ var IPython = (function (IPython) { }); }; - TextCell.prototype.handle_keyevent = function (editor, event) { - - // console.log('CM', this.mode, event.which, event.type) - - if (this.mode === 'command') { - return true; - } else if (this.mode === 'edit') { - return this.handle_codemirror_keyevent(editor, event); - } - }; - /** * This method gets called in CodeMirror's onKeyDown/onKeyPress * handlers and is used to provide custom key handling. * - * Subclass should override this method to have custom handeling + * Subclass should override this method to have custom handling * * @method handle_codemirror_keyevent * @param {CodeMirror} editor - The codemirror instance bound to the cell