Skip to content

Commit

Permalink
Re-focus old activeElement after patchDisplay
Browse files Browse the repository at this point in the history
It may have been a widget that was removed and put back again, thus
losing focus.

Issue #1094
  • Loading branch information
marijnh committed Dec 18, 2012
1 parent 4bdf569 commit 3e3eeba
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/codemirror.js
Expand Up @@ -531,7 +531,7 @@ window.CodeMirror = (function() {
}

function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
var dims = getDimensions(cm);
var dims = getDimensions(cm), focused = document.activeElement;
var display = cm.display, lineNumbers = cm.options.lineNumbers;
// IE does bad things to nodes when .innerHTML = "" is used on a parent
// we still need widgets and markers intact to add back to the new content later
Expand Down Expand Up @@ -571,6 +571,8 @@ window.CodeMirror = (function() {
++lineNo;
});
while (cur) cur = rm(cur);

if (document.activeElement != focused && focused.offsetHeight) focused.focus();
}

function buildLineElement(cm, line, lineNo, dims) {
Expand Down

0 comments on commit 3e3eeba

Please sign in to comment.