1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-04 13:05:23 +02:00

CodeMirror upgrade to 5.38.0

This commit is contained in:
Harvey Kandola 2018-05-29 18:27:42 +01:00
parent 36be6243ad
commit cfe30dcde5
52 changed files with 905 additions and 413 deletions

View file

@ -19,8 +19,11 @@
+ (regexp.multiline ? "m" : "")
}
function ensureGlobal(regexp) {
return regexp.global ? regexp : new RegExp(regexp.source, regexpFlags(regexp) + "g")
function ensureFlags(regexp, flags) {
var current = regexpFlags(regexp), target = current
for (var i = 0; i < flags.length; i++) if (target.indexOf(flags.charAt(i)) == -1)
target += flags.charAt(i)
return current == target ? regexp : new RegExp(regexp.source, target)
}
function maybeMultiline(regexp) {
@ -28,7 +31,7 @@
}
function searchRegexpForward(doc, regexp, start) {
regexp = ensureGlobal(regexp)
regexp = ensureFlags(regexp, "g")
for (var line = start.line, ch = start.ch, last = doc.lastLine(); line <= last; line++, ch = 0) {
regexp.lastIndex = ch
var string = doc.getLine(line), match = regexp.exec(string)
@ -42,7 +45,7 @@
function searchRegexpForwardMultiline(doc, regexp, start) {
if (!maybeMultiline(regexp)) return searchRegexpForward(doc, regexp, start)
regexp = ensureGlobal(regexp)
regexp = ensureFlags(regexp, "gm")
var string, chunk = 1
for (var line = start.line, last = doc.lastLine(); line <= last;) {
// This grows the search buffer in exponentially-sized chunks
@ -51,6 +54,7 @@
// searching for something that has tons of matches), but at the
// same time, the amount of retries is limited.
for (var i = 0; i < chunk; i++) {
if (line > last) break
var curLine = doc.getLine(line++)
string = string == null ? curLine : string + "\n" + curLine
}
@ -81,7 +85,7 @@
}
function searchRegexpBackward(doc, regexp, start) {
regexp = ensureGlobal(regexp)
regexp = ensureFlags(regexp, "g")
for (var line = start.line, ch = start.ch, first = doc.firstLine(); line >= first; line--, ch = -1) {
var string = doc.getLine(line)
if (ch > -1) string = string.slice(0, ch)
@ -94,7 +98,7 @@
}
function searchRegexpBackwardMultiline(doc, regexp, start) {
regexp = ensureGlobal(regexp)
regexp = ensureFlags(regexp, "gm")
var string, chunk = 1
for (var line = start.line, first = doc.firstLine(); line >= first;) {
for (var i = 0; i < chunk; i++) {
@ -213,7 +217,7 @@
return (reverse ? searchStringBackward : searchStringForward)(doc, query, pos, caseFold)
}
} else {
query = ensureGlobal(query)
query = ensureFlags(query, "gm")
if (!options || options.multiline !== false)
this.matches = function(reverse, pos) {
return (reverse ? searchRegexpBackwardMultiline : searchRegexpForwardMultiline)(doc, query, pos)