mirror of
https://github.com/documize/community.git
synced 2025-07-22 06:39:43 +02:00
CodeMirror upgrade to 5.38.0
This commit is contained in:
parent
36be6243ad
commit
cfe30dcde5
52 changed files with 905 additions and 413 deletions
118
gui/public/codemirror/lib/codemirror.js
vendored
Executable file → Normal file
118
gui/public/codemirror/lib/codemirror.js
vendored
Executable file → Normal file
|
@ -746,6 +746,16 @@ function collapsedSpanAtSide(line, start) {
|
|||
function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
|
||||
function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
|
||||
|
||||
function collapsedSpanAround(line, ch) {
|
||||
var sps = sawCollapsedSpans && line.markedSpans, found
|
||||
if (sps) { for (var i = 0; i < sps.length; ++i) {
|
||||
var sp = sps[i]
|
||||
if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
|
||||
(!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker }
|
||||
} }
|
||||
return found
|
||||
}
|
||||
|
||||
// Test whether there exists a collapsed span that partially
|
||||
// overlaps (covers the start or end, but not both) of a new span.
|
||||
// Such overlap is not allowed.
|
||||
|
@ -2778,12 +2788,11 @@ function coordsChar(cm, x, y) {
|
|||
var lineObj = getLine(doc, lineN)
|
||||
for (;;) {
|
||||
var found = coordsCharInner(cm, lineObj, lineN, x, y)
|
||||
var merged = collapsedSpanAtEnd(lineObj)
|
||||
var mergedPos = merged && merged.find(0, true)
|
||||
if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
|
||||
{ lineN = lineNo(lineObj = mergedPos.to.line) }
|
||||
else
|
||||
{ return found }
|
||||
var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 ? 1 : 0))
|
||||
if (!collapsed) { return found }
|
||||
var rangeEnd = collapsed.find(1)
|
||||
if (rangeEnd.line == lineN) { return rangeEnd }
|
||||
lineObj = getLine(doc, lineN = rangeEnd.line)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3543,6 +3552,7 @@ var NativeScrollbars = function(place, scroll, cm) {
|
|||
this.cm = cm
|
||||
var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar")
|
||||
var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar")
|
||||
vert.tabIndex = horiz.tabIndex = -1
|
||||
place(vert); place(horiz)
|
||||
|
||||
on(vert, "scroll", function () {
|
||||
|
@ -4783,7 +4793,7 @@ function addChangeToHistory(doc, change, selAfter, opId) {
|
|||
|
||||
if ((hist.lastOp == opId ||
|
||||
hist.lastOrigin == change.origin && change.origin &&
|
||||
((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
|
||||
((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
|
||||
change.origin.charAt(0) == "*")) &&
|
||||
(cur = lastChangeEvent(hist, hist.lastOp == opId))) {
|
||||
// Merge this change into the last event
|
||||
|
@ -5212,7 +5222,8 @@ function makeChangeInner(doc, change) {
|
|||
|
||||
// Revert a change stored in a document's history.
|
||||
function makeChangeFromHistory(doc, type, allowSelectionOnly) {
|
||||
if (doc.cm && doc.cm.state.suppressEdits && !allowSelectionOnly) { return }
|
||||
var suppress = doc.cm && doc.cm.state.suppressEdits
|
||||
if (suppress && !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
|
||||
|
@ -5237,8 +5248,10 @@ function makeChangeFromHistory(doc, type, allowSelectionOnly) {
|
|||
return
|
||||
}
|
||||
selAfter = event
|
||||
}
|
||||
else { break }
|
||||
} else if (suppress) {
|
||||
source.push(event)
|
||||
return
|
||||
} else { break }
|
||||
}
|
||||
|
||||
// Build up a reverse change object to add to the opposite history
|
||||
|
@ -5714,7 +5727,7 @@ function addLineWidget(doc, handle, node, options) {
|
|||
}
|
||||
return true
|
||||
})
|
||||
signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle))
|
||||
if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)) }
|
||||
return widget
|
||||
}
|
||||
|
||||
|
@ -6573,11 +6586,11 @@ function onResize(cm) {
|
|||
}
|
||||
|
||||
var keyNames = {
|
||||
3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
|
||||
3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
|
||||
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
|
||||
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
|
||||
46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
|
||||
106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete",
|
||||
106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", 145: "ScrollLock",
|
||||
173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
|
||||
221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
|
||||
63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
|
||||
|
@ -6724,6 +6737,9 @@ function keyName(event, noShift) {
|
|||
if (presto && event.keyCode == 34 && event["char"]) { return false }
|
||||
var name = keyNames[event.keyCode]
|
||||
if (name == null || event.altGraphKey) { return false }
|
||||
// Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
|
||||
// so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
|
||||
if (event.keyCode == 3 && event.code) { name = event.code }
|
||||
return addModifierNames(name, event, noShift)
|
||||
}
|
||||
|
||||
|
@ -7306,8 +7322,8 @@ function leftButtonStartDrag(cm, event, pos, behavior) {
|
|||
var dragEnd = operation(cm, function (e) {
|
||||
if (webkit) { display.scroller.draggable = false }
|
||||
cm.state.draggingText = false
|
||||
off(document, "mouseup", dragEnd)
|
||||
off(document, "mousemove", mouseMove)
|
||||
off(display.wrapper.ownerDocument, "mouseup", dragEnd)
|
||||
off(display.wrapper.ownerDocument, "mousemove", mouseMove)
|
||||
off(display.scroller, "dragstart", dragStart)
|
||||
off(display.scroller, "drop", dragEnd)
|
||||
if (!moved) {
|
||||
|
@ -7316,7 +7332,7 @@ function leftButtonStartDrag(cm, event, pos, behavior) {
|
|||
{ extendSelection(cm.doc, pos, null, null, behavior.extend) }
|
||||
// Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
|
||||
if (webkit || ie && ie_version == 9)
|
||||
{ setTimeout(function () {document.body.focus(); display.input.focus()}, 20) }
|
||||
{ setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus()}, 20) }
|
||||
else
|
||||
{ display.input.focus() }
|
||||
}
|
||||
|
@ -7331,8 +7347,8 @@ function leftButtonStartDrag(cm, event, pos, behavior) {
|
|||
dragEnd.copy = !behavior.moveOnDrag
|
||||
// IE's approach to draggable
|
||||
if (display.scroller.dragDrop) { display.scroller.dragDrop() }
|
||||
on(document, "mouseup", dragEnd)
|
||||
on(document, "mousemove", mouseMove)
|
||||
on(display.wrapper.ownerDocument, "mouseup", dragEnd)
|
||||
on(display.wrapper.ownerDocument, "mousemove", mouseMove)
|
||||
on(display.scroller, "dragstart", dragStart)
|
||||
on(display.scroller, "drop", dragEnd)
|
||||
|
||||
|
@ -7464,19 +7480,19 @@ function leftButtonSelect(cm, event, start, behavior) {
|
|||
counter = Infinity
|
||||
e_preventDefault(e)
|
||||
display.input.focus()
|
||||
off(document, "mousemove", move)
|
||||
off(document, "mouseup", up)
|
||||
off(display.wrapper.ownerDocument, "mousemove", move)
|
||||
off(display.wrapper.ownerDocument, "mouseup", up)
|
||||
doc.history.lastSelOrigin = null
|
||||
}
|
||||
|
||||
var move = operation(cm, function (e) {
|
||||
if (!e_button(e)) { done(e) }
|
||||
if (e.buttons === 0 || !e_button(e)) { done(e) }
|
||||
else { extend(e) }
|
||||
})
|
||||
var up = operation(cm, done)
|
||||
cm.state.selectingText = up
|
||||
on(document, "mousemove", move)
|
||||
on(document, "mouseup", up)
|
||||
on(display.wrapper.ownerDocument, "mousemove", move)
|
||||
on(display.wrapper.ownerDocument, "mouseup", up)
|
||||
}
|
||||
|
||||
// Used when mouse-selecting to adjust the anchor to the proper side
|
||||
|
@ -7606,6 +7622,7 @@ function defineOptions(CodeMirror) {
|
|||
clearCaches(cm)
|
||||
regChange(cm)
|
||||
}, true)
|
||||
|
||||
option("lineSeparator", null, function (cm, val) {
|
||||
cm.doc.lineSep = val
|
||||
if (!val) { return }
|
||||
|
@ -8012,7 +8029,7 @@ function applyTextInput(cm, inserted, deleted, sel, origin) {
|
|||
|
||||
var paste = cm.state.pasteIncoming || origin == "paste"
|
||||
var textLines = splitLinesAuto(inserted), multiPaste = null
|
||||
// When pasing N lines into N selections, insert one line per selection
|
||||
// When pasting N lines into N selections, insert one line per selection
|
||||
if (paste && sel.ranges.length > 1) {
|
||||
if (lastCopied && lastCopied.text.join("\n") == inserted) {
|
||||
if (sel.ranges.length % lastCopied.text.length == 0) {
|
||||
|
@ -8748,8 +8765,12 @@ ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
|
|||
this.showMultipleSelections(info)
|
||||
};
|
||||
|
||||
ContentEditableInput.prototype.getSelection = function () {
|
||||
return this.cm.display.wrapper.ownerDocument.getSelection()
|
||||
};
|
||||
|
||||
ContentEditableInput.prototype.showPrimarySelection = function () {
|
||||
var sel = window.getSelection(), cm = this.cm, prim = cm.doc.sel.primary()
|
||||
var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary()
|
||||
var from = prim.from(), to = prim.to()
|
||||
|
||||
if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
|
||||
|
@ -8816,13 +8837,13 @@ ContentEditableInput.prototype.showMultipleSelections = function (info) {
|
|||
};
|
||||
|
||||
ContentEditableInput.prototype.rememberSelection = function () {
|
||||
var sel = window.getSelection()
|
||||
var sel = this.getSelection()
|
||||
this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset
|
||||
this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset
|
||||
};
|
||||
|
||||
ContentEditableInput.prototype.selectionInEditor = function () {
|
||||
var sel = window.getSelection()
|
||||
var sel = this.getSelection()
|
||||
if (!sel.rangeCount) { return false }
|
||||
var node = sel.getRangeAt(0).commonAncestorContainer
|
||||
return contains(this.div, node)
|
||||
|
@ -8857,14 +8878,14 @@ ContentEditableInput.prototype.receivedFocus = function () {
|
|||
};
|
||||
|
||||
ContentEditableInput.prototype.selectionChanged = function () {
|
||||
var sel = window.getSelection()
|
||||
var sel = this.getSelection()
|
||||
return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
|
||||
sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
|
||||
};
|
||||
|
||||
ContentEditableInput.prototype.pollSelection = function () {
|
||||
if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
|
||||
var sel = window.getSelection(), cm = this.cm
|
||||
var sel = this.getSelection(), cm = this.cm
|
||||
// On Android Chrome (version 56, at least), backspacing into an
|
||||
// uneditable block element will put the cursor in that element,
|
||||
// and then, because it's not editable, hide the virtual keyboard.
|
||||
|
@ -8998,7 +9019,7 @@ ContentEditableInput.prototype.setUneditable = function (node) {
|
|||
};
|
||||
|
||||
ContentEditableInput.prototype.onKeyPress = function (e) {
|
||||
if (e.charCode == 0) { return }
|
||||
if (e.charCode == 0 || this.composing) { return }
|
||||
e.preventDefault()
|
||||
if (!this.cm.isReadOnly())
|
||||
{ operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0) }
|
||||
|
@ -9038,12 +9059,13 @@ function isInGutter(node) {
|
|||
function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
|
||||
|
||||
function domTextBetween(cm, from, to, fromLine, toLine) {
|
||||
var text = "", closing = false, lineSep = cm.doc.lineSeparator()
|
||||
var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false
|
||||
function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
|
||||
function close() {
|
||||
if (closing) {
|
||||
text += lineSep
|
||||
closing = false
|
||||
if (extraLinebreak) { text += lineSep }
|
||||
closing = extraLinebreak = false
|
||||
}
|
||||
}
|
||||
function addText(str) {
|
||||
|
@ -9055,8 +9077,8 @@ function domTextBetween(cm, from, to, fromLine, toLine) {
|
|||
function walk(node) {
|
||||
if (node.nodeType == 1) {
|
||||
var cmText = node.getAttribute("cm-text")
|
||||
if (cmText != null) {
|
||||
addText(cmText || node.textContent.replace(/\u200b/g, ""))
|
||||
if (cmText) {
|
||||
addText(cmText)
|
||||
return
|
||||
}
|
||||
var markerID = node.getAttribute("cm-marker"), range
|
||||
|
@ -9067,19 +9089,24 @@ function domTextBetween(cm, from, to, fromLine, toLine) {
|
|||
return
|
||||
}
|
||||
if (node.getAttribute("contenteditable") == "false") { return }
|
||||
var isBlock = /^(pre|div|p)$/i.test(node.nodeName)
|
||||
var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName)
|
||||
if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
|
||||
|
||||
if (isBlock) { close() }
|
||||
for (var i = 0; i < node.childNodes.length; i++)
|
||||
{ walk(node.childNodes[i]) }
|
||||
|
||||
if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true }
|
||||
if (isBlock) { closing = true }
|
||||
} else if (node.nodeType == 3) {
|
||||
addText(node.nodeValue)
|
||||
addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "))
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
walk(from)
|
||||
if (from == to) { break }
|
||||
from = from.nextSibling
|
||||
extraLinebreak = false
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
@ -9180,13 +9207,10 @@ TextareaInput.prototype.init = function (display) {
|
|||
var this$1 = this;
|
||||
|
||||
var input = this, cm = this.cm
|
||||
this.createField(display)
|
||||
var te = this.textarea
|
||||
|
||||
// Wraps and hides input textarea
|
||||
var div = this.wrapper = hiddenTextarea()
|
||||
// The semihidden textarea that is focused when the editor is
|
||||
// focused, and receives input.
|
||||
var te = this.textarea = div.firstChild
|
||||
display.wrapper.insertBefore(div, display.wrapper.firstChild)
|
||||
display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild)
|
||||
|
||||
// Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
|
||||
if (ios) { te.style.width = "0px" }
|
||||
|
@ -9253,6 +9277,14 @@ TextareaInput.prototype.init = function (display) {
|
|||
})
|
||||
};
|
||||
|
||||
TextareaInput.prototype.createField = function (_display) {
|
||||
// Wraps and hides input textarea
|
||||
this.wrapper = hiddenTextarea()
|
||||
// The semihidden textarea that is focused when the editor is
|
||||
// focused, and receives input.
|
||||
this.textarea = this.wrapper.firstChild
|
||||
};
|
||||
|
||||
TextareaInput.prototype.prepareSelection = function () {
|
||||
// Redraw the selection and/or cursor
|
||||
var cm = this.cm, display = cm.display, doc = cm.doc
|
||||
|
@ -9646,7 +9678,7 @@ CodeMirror.fromTextArea = fromTextArea
|
|||
|
||||
addLegacyProps(CodeMirror)
|
||||
|
||||
CodeMirror.version = "5.32.0"
|
||||
CodeMirror.version = "5.38.0"
|
||||
|
||||
return CodeMirror;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue