From 5f4d4017c1784a935dcfcbaa1c0e1b9ac63643b6 Mon Sep 17 00:00:00 2001 From: "Brian E. Granger" Date: Wed, 29 Jan 2014 11:46:18 -0800 Subject: [PATCH] Only call CM.focus() if CM is not already focused. --- IPython/html/static/notebook/js/cell.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/notebook/js/cell.js b/IPython/html/static/notebook/js/cell.js index c14a12595..f8fc9f963 100644 --- a/IPython/html/static/notebook/js/cell.js +++ b/IPython/html/static/notebook/js/cell.js @@ -288,8 +288,16 @@ var IPython = (function (IPython) { * @method focus_editor */ Cell.prototype.focus_editor = function () { + var that = this; this.refresh(); - this.code_mirror.focus(); + // Only focus the CM editor if it is not focused already. This prevents jumps + // related to the previous prompt position. + setTimeout(function () { + var isf = IPython.utils.is_focused; + if (!isf(that.element.find('div.CodeMirror'))) { + this.code_mirror.focus(); + } + }, 1); } /**