X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/a48175e69474b76a9aa2443ec7b2e8e9d68df1aa..3e25eb8de00f8d172b3ed2cfbb236e1e672426a0:/project/static/js/lib/codemirror/codemirror.js?ds=inline diff --git a/project/static/js/lib/codemirror/codemirror.js b/project/static/js/lib/codemirror/codemirror.js index 97e2657b..5567f66f 100644 --- a/project/static/js/lib/codemirror/codemirror.js +++ b/project/static/js/lib/codemirror/codemirror.js @@ -81,13 +81,10 @@ var CodeMirror = (function(){ var nextNum = 1, barWidth = null; function sizeBar() { - if (!frame.offsetWidth || !win.Editor) { - for (var cur = frame; cur.parentNode; cur = cur.parentNode) { - if (cur != document) { - clearInterval(sizeInterval); - return; - } - } + for (var root = frame; root.parentNode; root = root.parentNode); + if (root != document || !win.Editor) { + clearInterval(sizeInterval); + return; } if (nums.offsetWidth != barWidth) { @@ -175,10 +172,14 @@ var CodeMirror = (function(){ getCode: function() {return this.editor.getCode();}, setCode: function(code) {this.editor.importCode(code);}, - selection: function() {return this.editor.selectedText();}, + selection: function() {this.focusIfIE(); return this.editor.selectedText();}, reindent: function() {this.editor.reindent();}, - reindentSelection: function() {this.editor.reindentSelection(null);}, + reindentSelection: function() {this.focusIfIE(); this.editor.reindentSelection(null);}, + focusIfIE: function() { + // in IE, a lot of selection-related functionality only works when the frame is focused + if (this.win.select.ie_selection) this.focus(); + }, focus: function() { this.win.focus(); if (this.editor.selectionSnapshot) // IE hack @@ -206,10 +207,7 @@ var CodeMirror = (function(){ setParser: function(name) {this.editor.setParser(name);}, - cursorPosition: function(start) { - if (this.win.select.ie_selection) this.focus(); - return this.editor.cursorPosition(start); - }, + cursorPosition: function(start) {this.focusIfIE(); return this.editor.cursorPosition(start);}, firstLine: function() {return this.editor.firstLine();}, lastLine: function() {return this.editor.lastLine();}, nextLine: function(line) {return this.editor.nextLine(line);},