From 1490eafdd26a576dcc3832d1811802c0162dfe84 Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Sat, 30 Jul 2016 12:25:24 +0800 Subject: Update CodeMirror to version 5.17.1 --- public/vendor/codemirror/lib/codemirror.css | 11 ++++- public/vendor/codemirror/lib/codemirror.js | 73 ++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 24 deletions(-) (limited to 'public/vendor/codemirror/lib') diff --git a/public/vendor/codemirror/lib/codemirror.css b/public/vendor/codemirror/lib/codemirror.css index 4bd815eb..18b0bf70 100644 --- a/public/vendor/codemirror/lib/codemirror.css +++ b/public/vendor/codemirror/lib/codemirror.css @@ -88,8 +88,14 @@ .cm-tab { display: inline-block; text-decoration: inherit; } +.CodeMirror-rulers { + position: absolute; + left: 0; right: 0; top: -50px; bottom: -20px; + overflow: hidden; +} .CodeMirror-ruler { border-left: 1px solid #ccc; + top: 0; bottom: 0; position: absolute; } @@ -291,7 +297,10 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} visibility: hidden; } -.CodeMirror-cursor { position: absolute; } +.CodeMirror-cursor { + position: absolute; + pointer-events: none; +} .CodeMirror-measure pre { position: static; } div.CodeMirror-cursors { diff --git a/public/vendor/codemirror/lib/codemirror.js b/public/vendor/codemirror/lib/codemirror.js index 16497e5c..2c7829b2 100644 --- a/public/vendor/codemirror/lib/codemirror.js +++ b/public/vendor/codemirror/lib/codemirror.js @@ -1221,7 +1221,7 @@ }; function hiddenTextarea() { - var te = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none"); + var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none"); var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;"); // The textarea is kept positioned near the cursor to prevent the // fact that it'll be scrolled into view on input from scrolling @@ -2700,6 +2700,16 @@ return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}; } + function getUsefulRect(rects, bias) { + var rect = nullRect + if (bias == "left") for (var i = 0; i < rects.length; i++) { + if ((rect = rects[i]).left != rect.right) break + } else for (var i = rects.length - 1; i >= 0; i--) { + if ((rect = rects[i]).left != rect.right) break + } + return rect + } + function measureCharInner(cm, prepared, ch, bias) { var place = nodeAndOffsetInLineMap(prepared.map, ch, bias); var node = place.node, start = place.start, end = place.end, collapse = place.collapse; @@ -2709,17 +2719,10 @@ for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) --start; while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) ++end; - if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) { + if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) rect = node.parentNode.getBoundingClientRect(); - } else if (ie && cm.options.lineWrapping) { - var rects = range(node, start, end).getClientRects(); - if (rects.length) - rect = rects[bias == "right" ? rects.length - 1 : 0]; - else - rect = nullRect; - } else { - rect = range(node, start, end).getBoundingClientRect() || nullRect; - } + else + rect = getUsefulRect(range(node, start, end).getClientRects(), bias) if (rect.left || rect.right || start == 0) break; end = start; start = start - 1; @@ -2945,10 +2948,23 @@ for (;;) { if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) { var ch = x < fromX || x - fromX <= toX - x ? from : to; + var outside = ch == from ? fromOutside : toOutside var xDiff = x - (ch == from ? fromX : toX); + // This is a kludge to handle the case where the coordinates + // are after a line-wrapped line. We should replace it with a + // more general handling of cursor positions around line + // breaks. (Issue #4078) + if (toOutside && !bidi && !/\s/.test(lineObj.text.charAt(ch)) && xDiff > 0 && + ch < lineObj.text.length && preparedMeasure.view.measure.heights.length > 1) { + var charSize = measureCharPrepared(cm, preparedMeasure, ch, "right"); + if (innerOff <= charSize.bottom && innerOff >= charSize.top && Math.abs(x - charSize.right) < xDiff) { + outside = false + ch++ + xDiff = x - charSize.right + } + } while (isExtendingChar(lineObj.text.charAt(ch))) ++ch; - var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside, - xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0); + var pos = PosWithInfo(lineNo, ch, outside, xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0); return pos; } var step = Math.ceil(dist / 2), middle = from + step; @@ -3672,6 +3688,7 @@ // Let the drag handler handle this. if (webkit) display.scroller.draggable = true; cm.state.draggingText = dragEnd; + dragEnd.copy = mac ? e.altKey : e.ctrlKey // IE's approach to draggable if (display.scroller.dragDrop) display.scroller.dragDrop(); on(document, "mouseup", dragEnd); @@ -3902,7 +3919,7 @@ try { var text = e.dataTransfer.getData("Text"); if (text) { - if (cm.state.draggingText && !(mac ? e.altKey : e.ctrlKey)) + if (cm.state.draggingText && !cm.state.draggingText.copy) var selected = cm.listSelections(); setSelectionNoUndo(cm.doc, simpleSelection(pos, pos)); if (selected) for (var i = 0; i < selected.length; ++i) @@ -4417,7 +4434,7 @@ // Revert a change stored in a document's history. function makeChangeFromHistory(doc, type, allowSelectionOnly) { - if (doc.cm && doc.cm.state.suppressEdits) return; + if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) return; var hist = doc.history, event, selAfter = doc.sel; var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done; @@ -6942,6 +6959,7 @@ var content = elt("span", null, null, webkit ? "padding-right: .1px" : null); var builder = {pre: elt("pre", [content], "CodeMirror-line"), content: content, col: 0, pos: 0, cm: cm, + trailingSpace: false, splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")}; lineView.measure = {}; @@ -7003,7 +7021,7 @@ // the line map. Takes care to render special characters separately. function buildToken(builder, text, style, startStyle, endStyle, title, css) { if (!text) return; - var displayText = builder.splitSpaces ? text.replace(/ {3,}/g, splitSpaces) : text; + var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text var special = builder.cm.state.specialChars, mustWrap = false; if (!special.test(text)) { builder.col += text.length; @@ -7048,6 +7066,7 @@ builder.pos++; } } + builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32 if (style || startStyle || endStyle || mustWrap || css) { var fullStyle = style || ""; if (startStyle) fullStyle += startStyle; @@ -7059,11 +7078,17 @@ builder.content.appendChild(content); } - function splitSpaces(old) { - var out = " "; - for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0"; - out += " "; - return out; + function splitSpaces(text, trailingBefore) { + if (text.length > 1 && !/ /.test(text)) return text + var spaceBefore = trailingBefore, result = "" + for (var i = 0; i < text.length; i++) { + var ch = text.charAt(i) + if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32)) + ch = "\u00a0" + result += ch + spaceBefore = ch == " " + } + return result } // Work around nonsense dimensions being reported for stretches of @@ -7100,6 +7125,7 @@ builder.content.appendChild(widget); } builder.pos += size; + builder.trailingSpace = false } // Outputs a number of spans to make up a line, taking highlighting @@ -8548,8 +8574,9 @@ if (badBidiRects != null) return badBidiRects; var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA")); var r0 = range(txt, 0, 1).getBoundingClientRect(); - if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780) var r1 = range(txt, 1, 2).getBoundingClientRect(); + removeChildren(measure); + if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780) return badBidiRects = (r1.right - r0.right < 3); } @@ -8915,7 +8942,7 @@ // THE END - CodeMirror.version = "5.15.3"; + CodeMirror.version = "5.17.1"; return CodeMirror; }); -- cgit v1.2.3