|
|
@@ -13,6 +13,7 @@ window.CodeMirror = (function() {
|
|
|
var old_ie = /MSIE \d/.test(navigator.userAgent);
|
|
|
var ie_lt8 = old_ie && (document.documentMode == null || document.documentMode < 8);
|
|
|
var ie_lt9 = old_ie && (document.documentMode == null || document.documentMode < 9);
|
|
|
+ var ie_lt10 = old_ie && (document.documentMode == null || document.documentMode < 10);
|
|
|
var ie_gt10 = /Trident\/([7-9]|\d{2,})\./.test(navigator.userAgent);
|
|
|
var ie = old_ie || ie_gt10;
|
|
|
var webkit = /WebKit\//.test(navigator.userAgent);
|
|
|
@@ -99,7 +100,7 @@ window.CodeMirror = (function() {
|
|
|
function makeDisplay(place, docStart) {
|
|
|
var d = {};
|
|
|
|
|
|
- var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none; font-size: 4px;");
|
|
|
+ var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
|
|
|
if (webkit) input.style.width = "1000px";
|
|
|
else input.setAttribute("wrap", "off");
|
|
|
// if border: 0; -- iOS fails to open keyboard (issue #1287)
|
|
|
@@ -171,7 +172,7 @@ window.CodeMirror = (function() {
|
|
|
// Self-resetting timeout for the poller
|
|
|
d.poll = new Delayed();
|
|
|
|
|
|
- d.cachedCharWidth = d.cachedTextHeight = null;
|
|
|
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
|
|
|
d.measureLineCache = [];
|
|
|
d.measureLineCachePos = 0;
|
|
|
|
|
|
@@ -819,12 +820,12 @@ window.CodeMirror = (function() {
|
|
|
function updateSelectionRange(cm) {
|
|
|
var display = cm.display, doc = cm.doc, sel = cm.doc.sel;
|
|
|
var fragment = document.createDocumentFragment();
|
|
|
- var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);
|
|
|
+ var padding = paddingH(cm.display), leftSide = padding.left, rightSide = display.lineSpace.offsetWidth - padding.right;
|
|
|
|
|
|
function add(left, top, width, bottom) {
|
|
|
if (top < 0) top = 0;
|
|
|
fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
|
|
|
- "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
|
|
|
+ "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
|
|
|
"px; height: " + (bottom - top) + "px"));
|
|
|
}
|
|
|
|
|
|
@@ -847,18 +848,18 @@ window.CodeMirror = (function() {
|
|
|
left = leftPos.left;
|
|
|
right = rightPos.right;
|
|
|
}
|
|
|
- if (fromArg == null && from == 0) left = pl;
|
|
|
+ if (fromArg == null && from == 0) left = leftSide;
|
|
|
if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
|
|
|
add(left, leftPos.top, null, leftPos.bottom);
|
|
|
- left = pl;
|
|
|
+ left = leftSide;
|
|
|
if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
|
|
|
}
|
|
|
- if (toArg == null && to == lineLen) right = clientWidth;
|
|
|
+ if (toArg == null && to == lineLen) right = rightSide;
|
|
|
if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
|
|
|
start = leftPos;
|
|
|
if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
|
|
|
end = rightPos;
|
|
|
- if (left < pl + 1) left = pl;
|
|
|
+ if (left < leftSide + 1) left = leftSide;
|
|
|
add(left, rightPos.top, right - left, rightPos.bottom);
|
|
|
});
|
|
|
return {start: start, end: end};
|
|
|
@@ -874,13 +875,13 @@ window.CodeMirror = (function() {
|
|
|
if (singleVLine) {
|
|
|
if (leftEnd.top < rightStart.top - 2) {
|
|
|
add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
|
|
|
- add(pl, rightStart.top, rightStart.left, rightStart.bottom);
|
|
|
+ add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
|
|
|
} else {
|
|
|
add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
|
|
|
}
|
|
|
}
|
|
|
if (leftEnd.bottom < rightStart.top)
|
|
|
- add(pl, leftEnd.bottom, null, rightStart.top);
|
|
|
+ add(leftSide, leftEnd.bottom, null, rightStart.top);
|
|
|
}
|
|
|
|
|
|
removeChildrenAndAdd(display.selectionDiv, fragment);
|
|
|
@@ -983,9 +984,12 @@ window.CodeMirror = (function() {
|
|
|
|
|
|
function paddingTop(display) {return display.lineSpace.offsetTop;}
|
|
|
function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
|
|
|
- function paddingLeft(display) {
|
|
|
- var e = removeChildrenAndAdd(display.measure, elt("pre", null, null, "text-align: left")).appendChild(elt("span", "x"));
|
|
|
- return e.offsetLeft;
|
|
|
+ function paddingH(display) {
|
|
|
+ if (display.cachedPaddingH) return display.cachedPaddingH;
|
|
|
+ var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
|
|
|
+ var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
|
|
|
+ return display.cachedPaddingH = {left: parseInt(style.paddingLeft),
|
|
|
+ right: parseInt(style.paddingRight)};
|
|
|
}
|
|
|
|
|
|
function measureChar(cm, line, ch, data, bias) {
|
|
|
@@ -1159,7 +1163,7 @@ window.CodeMirror = (function() {
|
|
|
|
|
|
function clearCaches(cm) {
|
|
|
cm.display.measureLineCache.length = cm.display.measureLineCachePos = 0;
|
|
|
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = null;
|
|
|
+ cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
|
|
|
if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
|
|
|
cm.display.lineNumChars = null;
|
|
|
}
|
|
|
@@ -1375,7 +1379,7 @@ window.CodeMirror = (function() {
|
|
|
if (op.updateMaxLine) computeMaxLength(cm);
|
|
|
if (display.maxLineChanged && !cm.options.lineWrapping && display.maxLine) {
|
|
|
var width = measureLineWidth(cm, display.maxLine);
|
|
|
- display.sizer.style.minWidth = Math.max(0, width + 3 + scrollerCutOff) + "px";
|
|
|
+ display.sizer.style.minWidth = Math.max(0, width + 3) + "px";
|
|
|
display.maxLineChanged = false;
|
|
|
var maxScrollLeft = Math.max(0, display.sizer.offsetLeft + display.sizer.offsetWidth - display.scroller.clientWidth);
|
|
|
if (maxScrollLeft < doc.scrollLeft && !op.updateScrollPos)
|
|
|
@@ -1557,6 +1561,10 @@ window.CodeMirror = (function() {
|
|
|
cm.display.input.focus();
|
|
|
}
|
|
|
|
|
|
+ function ensureFocus(cm) {
|
|
|
+ if (!cm.state.focused) { focusInput(cm); onFocus(cm); }
|
|
|
+ }
|
|
|
+
|
|
|
function isReadOnly(cm) {
|
|
|
return cm.options.readOnly || cm.doc.cantEdit;
|
|
|
}
|
|
|
@@ -1613,7 +1621,7 @@ window.CodeMirror = (function() {
|
|
|
if (resizeTimer == null) resizeTimer = setTimeout(function() {
|
|
|
resizeTimer = null;
|
|
|
// Might be a text scaling operation, clear size caches.
|
|
|
- d.cachedCharWidth = d.cachedTextHeight = knownScrollbarWidth = null;
|
|
|
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = knownScrollbarWidth = null;
|
|
|
clearCaches(cm);
|
|
|
runInOp(cm, bind(regChange, cm));
|
|
|
}, 100);
|
|
|
@@ -1741,7 +1749,7 @@ window.CodeMirror = (function() {
|
|
|
// selection.
|
|
|
if (!start) {if (e_target(e) == display.scroller) e_preventDefault(e); return;}
|
|
|
|
|
|
- if (!cm.state.focused) onFocus(cm);
|
|
|
+ setTimeout(bind(ensureFocus, cm), 0);
|
|
|
|
|
|
var now = +new Date, type = "single";
|
|
|
if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
|
|
|
@@ -1821,7 +1829,7 @@ window.CodeMirror = (function() {
|
|
|
var cur = posFromMouse(cm, e, true);
|
|
|
if (!cur) return;
|
|
|
if (!posEq(cur, last)) {
|
|
|
- if (!cm.state.focused) onFocus(cm);
|
|
|
+ ensureFocus(cm);
|
|
|
last = cur;
|
|
|
doSelect(cur);
|
|
|
var visible = visibleLines(display, doc);
|
|
|
@@ -1846,7 +1854,7 @@ window.CodeMirror = (function() {
|
|
|
}
|
|
|
|
|
|
var move = operation(cm, function(e) {
|
|
|
- if (!old_ie && !e_button(e)) done(e);
|
|
|
+ if ((ie && !ie_lt10) ? !e.buttons : !e_button(e)) done(e);
|
|
|
else extend(e);
|
|
|
});
|
|
|
var up = operation(cm, done);
|
|
|
@@ -2149,7 +2157,7 @@ window.CodeMirror = (function() {
|
|
|
var lastStoppedKey = null;
|
|
|
function onKeyDown(e) {
|
|
|
var cm = this;
|
|
|
- if (!cm.state.focused) onFocus(cm);
|
|
|
+ ensureFocus(cm);
|
|
|
if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
|
|
|
if (old_ie && e.keyCode == 27) e.returnValue = false;
|
|
|
var code = e.keyCode;
|
|
|
@@ -2751,15 +2759,16 @@ window.CodeMirror = (function() {
|
|
|
// API UTILITIES
|
|
|
|
|
|
function indentLine(cm, n, how, aggressive) {
|
|
|
- var doc = cm.doc;
|
|
|
+ var doc = cm.doc, state;
|
|
|
if (how == null) how = "add";
|
|
|
if (how == "smart") {
|
|
|
if (!cm.doc.mode.indent) how = "prev";
|
|
|
- else var state = getStateBefore(cm, n);
|
|
|
+ else state = getStateBefore(cm, n);
|
|
|
}
|
|
|
|
|
|
var tabSize = cm.options.tabSize;
|
|
|
var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
|
|
|
+ if (line.stateAfter) line.stateAfter = null;
|
|
|
var curSpaceString = line.text.match(/^\s*/)[0], indentation;
|
|
|
if (!aggressive && !/\S/.test(line.text)) {
|
|
|
indentation = 0;
|
|
|
@@ -2834,13 +2843,15 @@ window.CodeMirror = (function() {
|
|
|
if (dir < 0 && !moveOnce(!first)) break;
|
|
|
var cur = lineObj.text.charAt(ch) || "\n";
|
|
|
var type = isWordChar(cur) ? "w"
|
|
|
- : !group ? null
|
|
|
- : /\s/.test(cur) ? null
|
|
|
+ : group && cur == "\n" ? "n"
|
|
|
+ : !group || /\s/.test(cur) ? null
|
|
|
: "p";
|
|
|
+ if (group && !first && !type) type = "s";
|
|
|
if (sawType && sawType != type) {
|
|
|
if (dir < 0) {dir = 1; moveOnce();}
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
if (type) sawType = type;
|
|
|
if (dir > 0 && !moveOnce(!first)) break;
|
|
|
}
|
|
|
@@ -3436,6 +3447,7 @@ window.CodeMirror = (function() {
|
|
|
spec = mimeModes[spec];
|
|
|
} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
|
|
|
var found = mimeModes[spec.name];
|
|
|
+ if (typeof found == "string") found = {name: found};
|
|
|
spec = createObj(found, spec);
|
|
|
spec.name = found.name;
|
|
|
} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
|
|
|
@@ -3548,7 +3560,7 @@ window.CodeMirror = (function() {
|
|
|
},
|
|
|
deleteLine: function(cm) {
|
|
|
var l = cm.getCursor().line;
|
|
|
- cm.replaceRange("", Pos(l, 0), Pos(l), "+delete");
|
|
|
+ cm.replaceRange("", Pos(l, 0), Pos(l + 1, 0), "+delete");
|
|
|
},
|
|
|
delLineLeft: function(cm) {
|
|
|
var cur = cm.getCursor();
|
|
|
@@ -3891,6 +3903,7 @@ window.CodeMirror = (function() {
|
|
|
this.doc.cantEdit = false;
|
|
|
if (cm) reCheckSelection(cm);
|
|
|
}
|
|
|
+ signalLater(cm, "markerCleared", cm, this);
|
|
|
if (withOp) endOperation(cm);
|
|
|
};
|
|
|
|
|
|
@@ -4000,6 +4013,7 @@ window.CodeMirror = (function() {
|
|
|
regChange(cm, from.line, to.line + 1);
|
|
|
if (marker.atomic) reCheckSelection(cm);
|
|
|
}
|
|
|
+ signalLater(cm, "markerAdded", cm, marker);
|
|
|
return marker;
|
|
|
}
|
|
|
|
|
|
@@ -4356,6 +4370,7 @@ window.CodeMirror = (function() {
|
|
|
var aboveVisible = heightAtLine(cm, line) < cm.doc.scrollTop;
|
|
|
updateLineHeight(line, line.height + widgetHeight(widget));
|
|
|
if (aboveVisible) addToScrollPos(cm, 0, widget.height);
|
|
|
+ cm.curOp.forceUpdate = true;
|
|
|
}
|
|
|
return true;
|
|
|
});
|
|
|
@@ -5059,6 +5074,22 @@ window.CodeMirror = (function() {
|
|
|
}
|
|
|
return markers;
|
|
|
},
|
|
|
+ findMarks: function(from, to) {
|
|
|
+ from = clipPos(this, from); to = clipPos(this, to);
|
|
|
+ var found = [], lineNo = from.line;
|
|
|
+ this.iter(from.line, to.line + 1, function(line) {
|
|
|
+ var spans = line.markedSpans;
|
|
|
+ if (spans) for (var i = 0; i < spans.length; i++) {
|
|
|
+ var span = spans[i];
|
|
|
+ if (!(lineNo == from.line && from.ch > span.to ||
|
|
|
+ span.from == null && lineNo != from.line||
|
|
|
+ lineNo == to.line && span.from > to.ch))
|
|
|
+ found.push(span.marker.parent || span.marker);
|
|
|
+ }
|
|
|
+ ++lineNo;
|
|
|
+ });
|
|
|
+ return found;
|
|
|
+ },
|
|
|
getAllMarks: function() {
|
|
|
var markers = [];
|
|
|
this.iter(function(line) {
|
|
|
@@ -5615,7 +5646,7 @@ window.CodeMirror = (function() {
|
|
|
return function(){return f.apply(null, args);};
|
|
|
}
|
|
|
|
|
|
- var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
|
|
|
+ var nonASCIISingleCaseWordChar = /[\u00df\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
|
|
|
function isWordChar(ch) {
|
|
|
return /\w/.test(ch) || ch > "\x80" &&
|
|
|
(ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
|
|
|
@@ -6056,7 +6087,7 @@ window.CodeMirror = (function() {
|
|
|
|
|
|
// THE END
|
|
|
|
|
|
- CodeMirror.version = "3.21.1";
|
|
|
+ CodeMirror.version = "3.22.1";
|
|
|
|
|
|
return CodeMirror;
|
|
|
})();
|