Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-file-.../lib/codemirr.../lib
File: codemirror.js
} else {
[7000] Fix | Delete
(lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
[7001] Fix | Delete
(lineView.measure.caches || (lineView.measure.caches = [])).push({});
[7002] Fix | Delete
}
[7003] Fix | Delete
}
[7004] Fix | Delete
[7005] Fix | Delete
// See issue #2901
[7006] Fix | Delete
if (webkit) {
[7007] Fix | Delete
var last = builder.content.lastChild
[7008] Fix | Delete
if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
[7009] Fix | Delete
builder.content.className = "cm-tab-wrap-hack";
[7010] Fix | Delete
}
[7011] Fix | Delete
[7012] Fix | Delete
signal(cm, "renderLine", cm, lineView.line, builder.pre);
[7013] Fix | Delete
if (builder.pre.className)
[7014] Fix | Delete
builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
[7015] Fix | Delete
[7016] Fix | Delete
return builder;
[7017] Fix | Delete
}
[7018] Fix | Delete
[7019] Fix | Delete
function defaultSpecialCharPlaceholder(ch) {
[7020] Fix | Delete
var token = elt("span", "\u2022", "cm-invalidchar");
[7021] Fix | Delete
token.title = "\\u" + ch.charCodeAt(0).toString(16);
[7022] Fix | Delete
token.setAttribute("aria-label", token.title);
[7023] Fix | Delete
return token;
[7024] Fix | Delete
}
[7025] Fix | Delete
[7026] Fix | Delete
// Build up the DOM representation for a single token, and add it to
[7027] Fix | Delete
// the line map. Takes care to render special characters separately.
[7028] Fix | Delete
function buildToken(builder, text, style, startStyle, endStyle, title, css) {
[7029] Fix | Delete
if (!text) return;
[7030] Fix | Delete
var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text
[7031] Fix | Delete
var special = builder.cm.state.specialChars, mustWrap = false;
[7032] Fix | Delete
if (!special.test(text)) {
[7033] Fix | Delete
builder.col += text.length;
[7034] Fix | Delete
var content = document.createTextNode(displayText);
[7035] Fix | Delete
builder.map.push(builder.pos, builder.pos + text.length, content);
[7036] Fix | Delete
if (ie && ie_version < 9) mustWrap = true;
[7037] Fix | Delete
builder.pos += text.length;
[7038] Fix | Delete
} else {
[7039] Fix | Delete
var content = document.createDocumentFragment(), pos = 0;
[7040] Fix | Delete
while (true) {
[7041] Fix | Delete
special.lastIndex = pos;
[7042] Fix | Delete
var m = special.exec(text);
[7043] Fix | Delete
var skipped = m ? m.index - pos : text.length - pos;
[7044] Fix | Delete
if (skipped) {
[7045] Fix | Delete
var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
[7046] Fix | Delete
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
[7047] Fix | Delete
else content.appendChild(txt);
[7048] Fix | Delete
builder.map.push(builder.pos, builder.pos + skipped, txt);
[7049] Fix | Delete
builder.col += skipped;
[7050] Fix | Delete
builder.pos += skipped;
[7051] Fix | Delete
}
[7052] Fix | Delete
if (!m) break;
[7053] Fix | Delete
pos += skipped + 1;
[7054] Fix | Delete
if (m[0] == "\t") {
[7055] Fix | Delete
var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
[7056] Fix | Delete
var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
[7057] Fix | Delete
txt.setAttribute("role", "presentation");
[7058] Fix | Delete
txt.setAttribute("cm-text", "\t");
[7059] Fix | Delete
builder.col += tabWidth;
[7060] Fix | Delete
} else if (m[0] == "\r" || m[0] == "\n") {
[7061] Fix | Delete
var txt = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
[7062] Fix | Delete
txt.setAttribute("cm-text", m[0]);
[7063] Fix | Delete
builder.col += 1;
[7064] Fix | Delete
} else {
[7065] Fix | Delete
var txt = builder.cm.options.specialCharPlaceholder(m[0]);
[7066] Fix | Delete
txt.setAttribute("cm-text", m[0]);
[7067] Fix | Delete
if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
[7068] Fix | Delete
else content.appendChild(txt);
[7069] Fix | Delete
builder.col += 1;
[7070] Fix | Delete
}
[7071] Fix | Delete
builder.map.push(builder.pos, builder.pos + 1, txt);
[7072] Fix | Delete
builder.pos++;
[7073] Fix | Delete
}
[7074] Fix | Delete
}
[7075] Fix | Delete
builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32
[7076] Fix | Delete
if (style || startStyle || endStyle || mustWrap || css) {
[7077] Fix | Delete
var fullStyle = style || "";
[7078] Fix | Delete
if (startStyle) fullStyle += startStyle;
[7079] Fix | Delete
if (endStyle) fullStyle += endStyle;
[7080] Fix | Delete
var token = elt("span", [content], fullStyle, css);
[7081] Fix | Delete
if (title) token.title = title;
[7082] Fix | Delete
return builder.content.appendChild(token);
[7083] Fix | Delete
}
[7084] Fix | Delete
builder.content.appendChild(content);
[7085] Fix | Delete
}
[7086] Fix | Delete
[7087] Fix | Delete
function splitSpaces(text, trailingBefore) {
[7088] Fix | Delete
if (text.length > 1 && !/ /.test(text)) return text
[7089] Fix | Delete
var spaceBefore = trailingBefore, result = ""
[7090] Fix | Delete
for (var i = 0; i < text.length; i++) {
[7091] Fix | Delete
var ch = text.charAt(i)
[7092] Fix | Delete
if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
[7093] Fix | Delete
ch = "\u00a0"
[7094] Fix | Delete
result += ch
[7095] Fix | Delete
spaceBefore = ch == " "
[7096] Fix | Delete
}
[7097] Fix | Delete
return result
[7098] Fix | Delete
}
[7099] Fix | Delete
[7100] Fix | Delete
// Work around nonsense dimensions being reported for stretches of
[7101] Fix | Delete
// right-to-left text.
[7102] Fix | Delete
function buildTokenBadBidi(inner, order) {
[7103] Fix | Delete
return function(builder, text, style, startStyle, endStyle, title, css) {
[7104] Fix | Delete
style = style ? style + " cm-force-border" : "cm-force-border";
[7105] Fix | Delete
var start = builder.pos, end = start + text.length;
[7106] Fix | Delete
for (;;) {
[7107] Fix | Delete
// Find the part that overlaps with the start of this text
[7108] Fix | Delete
for (var i = 0; i < order.length; i++) {
[7109] Fix | Delete
var part = order[i];
[7110] Fix | Delete
if (part.to > start && part.from <= start) break;
[7111] Fix | Delete
}
[7112] Fix | Delete
if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title, css);
[7113] Fix | Delete
inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
[7114] Fix | Delete
startStyle = null;
[7115] Fix | Delete
text = text.slice(part.to - start);
[7116] Fix | Delete
start = part.to;
[7117] Fix | Delete
}
[7118] Fix | Delete
};
[7119] Fix | Delete
}
[7120] Fix | Delete
[7121] Fix | Delete
function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
[7122] Fix | Delete
var widget = !ignoreWidget && marker.widgetNode;
[7123] Fix | Delete
if (widget) builder.map.push(builder.pos, builder.pos + size, widget);
[7124] Fix | Delete
if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
[7125] Fix | Delete
if (!widget)
[7126] Fix | Delete
widget = builder.content.appendChild(document.createElement("span"));
[7127] Fix | Delete
widget.setAttribute("cm-marker", marker.id);
[7128] Fix | Delete
}
[7129] Fix | Delete
if (widget) {
[7130] Fix | Delete
builder.cm.display.input.setUneditable(widget);
[7131] Fix | Delete
builder.content.appendChild(widget);
[7132] Fix | Delete
}
[7133] Fix | Delete
builder.pos += size;
[7134] Fix | Delete
builder.trailingSpace = false
[7135] Fix | Delete
}
[7136] Fix | Delete
[7137] Fix | Delete
// Outputs a number of spans to make up a line, taking highlighting
[7138] Fix | Delete
// and marked text into account.
[7139] Fix | Delete
function insertLineContent(line, builder, styles) {
[7140] Fix | Delete
var spans = line.markedSpans, allText = line.text, at = 0;
[7141] Fix | Delete
if (!spans) {
[7142] Fix | Delete
for (var i = 1; i < styles.length; i+=2)
[7143] Fix | Delete
builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
[7144] Fix | Delete
return;
[7145] Fix | Delete
}
[7146] Fix | Delete
[7147] Fix | Delete
var len = allText.length, pos = 0, i = 1, text = "", style, css;
[7148] Fix | Delete
var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
[7149] Fix | Delete
for (;;) {
[7150] Fix | Delete
if (nextChange == pos) { // Update current marker set
[7151] Fix | Delete
spanStyle = spanEndStyle = spanStartStyle = title = css = "";
[7152] Fix | Delete
collapsed = null; nextChange = Infinity;
[7153] Fix | Delete
var foundBookmarks = [], endStyles
[7154] Fix | Delete
for (var j = 0; j < spans.length; ++j) {
[7155] Fix | Delete
var sp = spans[j], m = sp.marker;
[7156] Fix | Delete
if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
[7157] Fix | Delete
foundBookmarks.push(m);
[7158] Fix | Delete
} else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
[7159] Fix | Delete
if (sp.to != null && sp.to != pos && nextChange > sp.to) {
[7160] Fix | Delete
nextChange = sp.to;
[7161] Fix | Delete
spanEndStyle = "";
[7162] Fix | Delete
}
[7163] Fix | Delete
if (m.className) spanStyle += " " + m.className;
[7164] Fix | Delete
if (m.css) css = (css ? css + ";" : "") + m.css;
[7165] Fix | Delete
if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
[7166] Fix | Delete
if (m.endStyle && sp.to == nextChange) (endStyles || (endStyles = [])).push(m.endStyle, sp.to)
[7167] Fix | Delete
if (m.title && !title) title = m.title;
[7168] Fix | Delete
if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
[7169] Fix | Delete
collapsed = sp;
[7170] Fix | Delete
} else if (sp.from > pos && nextChange > sp.from) {
[7171] Fix | Delete
nextChange = sp.from;
[7172] Fix | Delete
}
[7173] Fix | Delete
}
[7174] Fix | Delete
if (endStyles) for (var j = 0; j < endStyles.length; j += 2)
[7175] Fix | Delete
if (endStyles[j + 1] == nextChange) spanEndStyle += " " + endStyles[j]
[7176] Fix | Delete
[7177] Fix | Delete
if (!collapsed || collapsed.from == pos) for (var j = 0; j < foundBookmarks.length; ++j)
[7178] Fix | Delete
buildCollapsedSpan(builder, 0, foundBookmarks[j]);
[7179] Fix | Delete
if (collapsed && (collapsed.from || 0) == pos) {
[7180] Fix | Delete
buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
[7181] Fix | Delete
collapsed.marker, collapsed.from == null);
[7182] Fix | Delete
if (collapsed.to == null) return;
[7183] Fix | Delete
if (collapsed.to == pos) collapsed = false;
[7184] Fix | Delete
}
[7185] Fix | Delete
}
[7186] Fix | Delete
if (pos >= len) break;
[7187] Fix | Delete
[7188] Fix | Delete
var upto = Math.min(len, nextChange);
[7189] Fix | Delete
while (true) {
[7190] Fix | Delete
if (text) {
[7191] Fix | Delete
var end = pos + text.length;
[7192] Fix | Delete
if (!collapsed) {
[7193] Fix | Delete
var tokenText = end > upto ? text.slice(0, upto - pos) : text;
[7194] Fix | Delete
builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
[7195] Fix | Delete
spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
[7196] Fix | Delete
}
[7197] Fix | Delete
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
[7198] Fix | Delete
pos = end;
[7199] Fix | Delete
spanStartStyle = "";
[7200] Fix | Delete
}
[7201] Fix | Delete
text = allText.slice(at, at = styles[i++]);
[7202] Fix | Delete
style = interpretTokenStyle(styles[i++], builder.cm.options);
[7203] Fix | Delete
}
[7204] Fix | Delete
}
[7205] Fix | Delete
}
[7206] Fix | Delete
[7207] Fix | Delete
// DOCUMENT DATA STRUCTURE
[7208] Fix | Delete
[7209] Fix | Delete
// By default, updates that start and end at the beginning of a line
[7210] Fix | Delete
// are treated specially, in order to make the association of line
[7211] Fix | Delete
// widgets and marker elements with the text behave more intuitive.
[7212] Fix | Delete
function isWholeLineUpdate(doc, change) {
[7213] Fix | Delete
return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
[7214] Fix | Delete
(!doc.cm || doc.cm.options.wholeLineUpdateBefore);
[7215] Fix | Delete
}
[7216] Fix | Delete
[7217] Fix | Delete
// Perform a change on the document data structure.
[7218] Fix | Delete
function updateDoc(doc, change, markedSpans, estimateHeight) {
[7219] Fix | Delete
function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
[7220] Fix | Delete
function update(line, text, spans) {
[7221] Fix | Delete
updateLine(line, text, spans, estimateHeight);
[7222] Fix | Delete
signalLater(line, "change", line, change);
[7223] Fix | Delete
}
[7224] Fix | Delete
function linesFor(start, end) {
[7225] Fix | Delete
for (var i = start, result = []; i < end; ++i)
[7226] Fix | Delete
result.push(new Line(text[i], spansFor(i), estimateHeight));
[7227] Fix | Delete
return result;
[7228] Fix | Delete
}
[7229] Fix | Delete
[7230] Fix | Delete
var from = change.from, to = change.to, text = change.text;
[7231] Fix | Delete
var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
[7232] Fix | Delete
var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
[7233] Fix | Delete
[7234] Fix | Delete
// Adjust the line structure
[7235] Fix | Delete
if (change.full) {
[7236] Fix | Delete
doc.insert(0, linesFor(0, text.length));
[7237] Fix | Delete
doc.remove(text.length, doc.size - text.length);
[7238] Fix | Delete
} else if (isWholeLineUpdate(doc, change)) {
[7239] Fix | Delete
// This is a whole-line replace. Treated specially to make
[7240] Fix | Delete
// sure line objects move the way they are supposed to.
[7241] Fix | Delete
var added = linesFor(0, text.length - 1);
[7242] Fix | Delete
update(lastLine, lastLine.text, lastSpans);
[7243] Fix | Delete
if (nlines) doc.remove(from.line, nlines);
[7244] Fix | Delete
if (added.length) doc.insert(from.line, added);
[7245] Fix | Delete
} else if (firstLine == lastLine) {
[7246] Fix | Delete
if (text.length == 1) {
[7247] Fix | Delete
update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
[7248] Fix | Delete
} else {
[7249] Fix | Delete
var added = linesFor(1, text.length - 1);
[7250] Fix | Delete
added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
[7251] Fix | Delete
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
[7252] Fix | Delete
doc.insert(from.line + 1, added);
[7253] Fix | Delete
}
[7254] Fix | Delete
} else if (text.length == 1) {
[7255] Fix | Delete
update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
[7256] Fix | Delete
doc.remove(from.line + 1, nlines);
[7257] Fix | Delete
} else {
[7258] Fix | Delete
update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
[7259] Fix | Delete
update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
[7260] Fix | Delete
var added = linesFor(1, text.length - 1);
[7261] Fix | Delete
if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
[7262] Fix | Delete
doc.insert(from.line + 1, added);
[7263] Fix | Delete
}
[7264] Fix | Delete
[7265] Fix | Delete
signalLater(doc, "change", doc, change);
[7266] Fix | Delete
}
[7267] Fix | Delete
[7268] Fix | Delete
// The document is represented as a BTree consisting of leaves, with
[7269] Fix | Delete
// chunk of lines in them, and branches, with up to ten leaves or
[7270] Fix | Delete
// other branch nodes below them. The top node is always a branch
[7271] Fix | Delete
// node, and is the document object itself (meaning it has
[7272] Fix | Delete
// additional methods and properties).
[7273] Fix | Delete
//
[7274] Fix | Delete
// All nodes have parent links. The tree is used both to go from
[7275] Fix | Delete
// line numbers to line objects, and to go from objects to numbers.
[7276] Fix | Delete
// It also indexes by height, and is used to convert between height
[7277] Fix | Delete
// and line object, and to find the total height of the document.
[7278] Fix | Delete
//
[7279] Fix | Delete
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
[7280] Fix | Delete
[7281] Fix | Delete
function LeafChunk(lines) {
[7282] Fix | Delete
this.lines = lines;
[7283] Fix | Delete
this.parent = null;
[7284] Fix | Delete
for (var i = 0, height = 0; i < lines.length; ++i) {
[7285] Fix | Delete
lines[i].parent = this;
[7286] Fix | Delete
height += lines[i].height;
[7287] Fix | Delete
}
[7288] Fix | Delete
this.height = height;
[7289] Fix | Delete
}
[7290] Fix | Delete
[7291] Fix | Delete
LeafChunk.prototype = {
[7292] Fix | Delete
chunkSize: function() { return this.lines.length; },
[7293] Fix | Delete
// Remove the n lines at offset 'at'.
[7294] Fix | Delete
removeInner: function(at, n) {
[7295] Fix | Delete
for (var i = at, e = at + n; i < e; ++i) {
[7296] Fix | Delete
var line = this.lines[i];
[7297] Fix | Delete
this.height -= line.height;
[7298] Fix | Delete
cleanUpLine(line);
[7299] Fix | Delete
signalLater(line, "delete");
[7300] Fix | Delete
}
[7301] Fix | Delete
this.lines.splice(at, n);
[7302] Fix | Delete
},
[7303] Fix | Delete
// Helper used to collapse a small branch into a single leaf.
[7304] Fix | Delete
collapse: function(lines) {
[7305] Fix | Delete
lines.push.apply(lines, this.lines);
[7306] Fix | Delete
},
[7307] Fix | Delete
// Insert the given array of lines at offset 'at', count them as
[7308] Fix | Delete
// having the given height.
[7309] Fix | Delete
insertInner: function(at, lines, height) {
[7310] Fix | Delete
this.height += height;
[7311] Fix | Delete
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
[7312] Fix | Delete
for (var i = 0; i < lines.length; ++i) lines[i].parent = this;
[7313] Fix | Delete
},
[7314] Fix | Delete
// Used to iterate over a part of the tree.
[7315] Fix | Delete
iterN: function(at, n, op) {
[7316] Fix | Delete
for (var e = at + n; at < e; ++at)
[7317] Fix | Delete
if (op(this.lines[at])) return true;
[7318] Fix | Delete
}
[7319] Fix | Delete
};
[7320] Fix | Delete
[7321] Fix | Delete
function BranchChunk(children) {
[7322] Fix | Delete
this.children = children;
[7323] Fix | Delete
var size = 0, height = 0;
[7324] Fix | Delete
for (var i = 0; i < children.length; ++i) {
[7325] Fix | Delete
var ch = children[i];
[7326] Fix | Delete
size += ch.chunkSize(); height += ch.height;
[7327] Fix | Delete
ch.parent = this;
[7328] Fix | Delete
}
[7329] Fix | Delete
this.size = size;
[7330] Fix | Delete
this.height = height;
[7331] Fix | Delete
this.parent = null;
[7332] Fix | Delete
}
[7333] Fix | Delete
[7334] Fix | Delete
BranchChunk.prototype = {
[7335] Fix | Delete
chunkSize: function() { return this.size; },
[7336] Fix | Delete
removeInner: function(at, n) {
[7337] Fix | Delete
this.size -= n;
[7338] Fix | Delete
for (var i = 0; i < this.children.length; ++i) {
[7339] Fix | Delete
var child = this.children[i], sz = child.chunkSize();
[7340] Fix | Delete
if (at < sz) {
[7341] Fix | Delete
var rm = Math.min(n, sz - at), oldHeight = child.height;
[7342] Fix | Delete
child.removeInner(at, rm);
[7343] Fix | Delete
this.height -= oldHeight - child.height;
[7344] Fix | Delete
if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
[7345] Fix | Delete
if ((n -= rm) == 0) break;
[7346] Fix | Delete
at = 0;
[7347] Fix | Delete
} else at -= sz;
[7348] Fix | Delete
}
[7349] Fix | Delete
// If the result is smaller than 25 lines, ensure that it is a
[7350] Fix | Delete
// single leaf node.
[7351] Fix | Delete
if (this.size - n < 25 &&
[7352] Fix | Delete
(this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
[7353] Fix | Delete
var lines = [];
[7354] Fix | Delete
this.collapse(lines);
[7355] Fix | Delete
this.children = [new LeafChunk(lines)];
[7356] Fix | Delete
this.children[0].parent = this;
[7357] Fix | Delete
}
[7358] Fix | Delete
},
[7359] Fix | Delete
collapse: function(lines) {
[7360] Fix | Delete
for (var i = 0; i < this.children.length; ++i) this.children[i].collapse(lines);
[7361] Fix | Delete
},
[7362] Fix | Delete
insertInner: function(at, lines, height) {
[7363] Fix | Delete
this.size += lines.length;
[7364] Fix | Delete
this.height += height;
[7365] Fix | Delete
for (var i = 0; i < this.children.length; ++i) {
[7366] Fix | Delete
var child = this.children[i], sz = child.chunkSize();
[7367] Fix | Delete
if (at <= sz) {
[7368] Fix | Delete
child.insertInner(at, lines, height);
[7369] Fix | Delete
if (child.lines && child.lines.length > 50) {
[7370] Fix | Delete
// To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
[7371] Fix | Delete
// Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
[7372] Fix | Delete
var remaining = child.lines.length % 25 + 25
[7373] Fix | Delete
for (var pos = remaining; pos < child.lines.length;) {
[7374] Fix | Delete
var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
[7375] Fix | Delete
child.height -= leaf.height;
[7376] Fix | Delete
this.children.splice(++i, 0, leaf);
[7377] Fix | Delete
leaf.parent = this;
[7378] Fix | Delete
}
[7379] Fix | Delete
child.lines = child.lines.slice(0, remaining);
[7380] Fix | Delete
this.maybeSpill();
[7381] Fix | Delete
}
[7382] Fix | Delete
break;
[7383] Fix | Delete
}
[7384] Fix | Delete
at -= sz;
[7385] Fix | Delete
}
[7386] Fix | Delete
},
[7387] Fix | Delete
// When a node has grown, check whether it should be split.
[7388] Fix | Delete
maybeSpill: function() {
[7389] Fix | Delete
if (this.children.length <= 10) return;
[7390] Fix | Delete
var me = this;
[7391] Fix | Delete
do {
[7392] Fix | Delete
var spilled = me.children.splice(me.children.length - 5, 5);
[7393] Fix | Delete
var sibling = new BranchChunk(spilled);
[7394] Fix | Delete
if (!me.parent) { // Become the parent node
[7395] Fix | Delete
var copy = new BranchChunk(me.children);
[7396] Fix | Delete
copy.parent = me;
[7397] Fix | Delete
me.children = [copy, sibling];
[7398] Fix | Delete
me = copy;
[7399] Fix | Delete
} else {
[7400] Fix | Delete
me.size -= sibling.size;
[7401] Fix | Delete
me.height -= sibling.height;
[7402] Fix | Delete
var myIndex = indexOf(me.parent.children, me);
[7403] Fix | Delete
me.parent.children.splice(myIndex + 1, 0, sibling);
[7404] Fix | Delete
}
[7405] Fix | Delete
sibling.parent = me.parent;
[7406] Fix | Delete
} while (me.children.length > 10);
[7407] Fix | Delete
me.parent.maybeSpill();
[7408] Fix | Delete
},
[7409] Fix | Delete
iterN: function(at, n, op) {
[7410] Fix | Delete
for (var i = 0; i < this.children.length; ++i) {
[7411] Fix | Delete
var child = this.children[i], sz = child.chunkSize();
[7412] Fix | Delete
if (at < sz) {
[7413] Fix | Delete
var used = Math.min(n, sz - at);
[7414] Fix | Delete
if (child.iterN(at, used, op)) return true;
[7415] Fix | Delete
if ((n -= used) == 0) break;
[7416] Fix | Delete
at = 0;
[7417] Fix | Delete
} else at -= sz;
[7418] Fix | Delete
}
[7419] Fix | Delete
}
[7420] Fix | Delete
};
[7421] Fix | Delete
[7422] Fix | Delete
var nextDocId = 0;
[7423] Fix | Delete
var Doc = CodeMirror.Doc = function(text, mode, firstLine, lineSep) {
[7424] Fix | Delete
if (!(this instanceof Doc)) return new Doc(text, mode, firstLine, lineSep);
[7425] Fix | Delete
if (firstLine == null) firstLine = 0;
[7426] Fix | Delete
[7427] Fix | Delete
BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
[7428] Fix | Delete
this.first = firstLine;
[7429] Fix | Delete
this.scrollTop = this.scrollLeft = 0;
[7430] Fix | Delete
this.cantEdit = false;
[7431] Fix | Delete
this.cleanGeneration = 1;
[7432] Fix | Delete
this.frontier = firstLine;
[7433] Fix | Delete
var start = Pos(firstLine, 0);
[7434] Fix | Delete
this.sel = simpleSelection(start);
[7435] Fix | Delete
this.history = new History(null);
[7436] Fix | Delete
this.id = ++nextDocId;
[7437] Fix | Delete
this.modeOption = mode;
[7438] Fix | Delete
this.lineSep = lineSep;
[7439] Fix | Delete
this.extend = false;
[7440] Fix | Delete
[7441] Fix | Delete
if (typeof text == "string") text = this.splitLines(text);
[7442] Fix | Delete
updateDoc(this, {from: start, to: start, text: text});
[7443] Fix | Delete
setSelection(this, simpleSelection(start), sel_dontScroll);
[7444] Fix | Delete
};
[7445] Fix | Delete
[7446] Fix | Delete
Doc.prototype = createObj(BranchChunk.prototype, {
[7447] Fix | Delete
constructor: Doc,
[7448] Fix | Delete
// Iterate over the document. Supports two forms -- with only one
[7449] Fix | Delete
// argument, it calls that for each line in the document. With
[7450] Fix | Delete
// three, it iterates over the range given by the first two (with
[7451] Fix | Delete
// the second being non-inclusive).
[7452] Fix | Delete
iter: function(from, to, op) {
[7453] Fix | Delete
if (op) this.iterN(from - this.first, to - from, op);
[7454] Fix | Delete
else this.iterN(this.first, this.first + this.size, from);
[7455] Fix | Delete
},
[7456] Fix | Delete
[7457] Fix | Delete
// Non-public interface for adding and removing lines.
[7458] Fix | Delete
insert: function(at, lines) {
[7459] Fix | Delete
var height = 0;
[7460] Fix | Delete
for (var i = 0; i < lines.length; ++i) height += lines[i].height;
[7461] Fix | Delete
this.insertInner(at - this.first, lines, height);
[7462] Fix | Delete
},
[7463] Fix | Delete
remove: function(at, n) { this.removeInner(at - this.first, n); },
[7464] Fix | Delete
[7465] Fix | Delete
// From here, the methods are part of the public interface. Most
[7466] Fix | Delete
// are also available from CodeMirror (editor) instances.
[7467] Fix | Delete
[7468] Fix | Delete
getValue: function(lineSep) {
[7469] Fix | Delete
var lines = getLines(this, this.first, this.first + this.size);
[7470] Fix | Delete
if (lineSep === false) return lines;
[7471] Fix | Delete
return lines.join(lineSep || this.lineSeparator());
[7472] Fix | Delete
},
[7473] Fix | Delete
setValue: docMethodOp(function(code) {
[7474] Fix | Delete
var top = Pos(this.first, 0), last = this.first + this.size - 1;
[7475] Fix | Delete
makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
[7476] Fix | Delete
text: this.splitLines(code), origin: "setValue", full: true}, true);
[7477] Fix | Delete
setSelection(this, simpleSelection(top));
[7478] Fix | Delete
}),
[7479] Fix | Delete
replaceRange: function(code, from, to, origin) {
[7480] Fix | Delete
from = clipPos(this, from);
[7481] Fix | Delete
to = to ? clipPos(this, to) : from;
[7482] Fix | Delete
replaceRange(this, code, from, to, origin);
[7483] Fix | Delete
},
[7484] Fix | Delete
getRange: function(from, to, lineSep) {
[7485] Fix | Delete
var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
[7486] Fix | Delete
if (lineSep === false) return lines;
[7487] Fix | Delete
return lines.join(lineSep || this.lineSeparator());
[7488] Fix | Delete
},
[7489] Fix | Delete
[7490] Fix | Delete
getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
[7491] Fix | Delete
[7492] Fix | Delete
getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
[7493] Fix | Delete
getLineNumber: function(line) {return lineNo(line);},
[7494] Fix | Delete
[7495] Fix | Delete
getLineHandleVisualStart: function(line) {
[7496] Fix | Delete
if (typeof line == "number") line = getLine(this, line);
[7497] Fix | Delete
return visualLine(line);
[7498] Fix | Delete
},
[7499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function