in packages/osd-ace/src/ace/modes/x_json/worker/x_json.ace.worker.js [484:687]
oop.implement(this, EventEmitter), this.setValue = function(text) {
var len = this.getLength() - 1;
this.remove(new Range(0, 0, len, this.getLine(len).length)), this.insert({
row: 0,
column: 0
}, text)
}, this.getValue = function() {
return this.getAllLines().join(this.getNewLineCharacter())
}, this.createAnchor = function(row, column) {
return new Anchor(this, row, column)
}, this.$split = 0 === "aaa".split(/a/).length ? function(text) {
return text.replace(/\r\n|\r/g, "\n").split("\n")
} : function(text) {
return text.split(/\r\n|\r|\n/)
}, this.$detectNewLine = function(text) {
var match = text.match(/^.*?(\r\n|\r|\n)/m);
this.$autoNewLine = match ? match[1] : "\n", this._signal("changeNewLineMode")
}, this.getNewLineCharacter = function() {
switch (this.$newLineMode) {
case "windows":
return "\r\n";
case "unix":
return "\n";
default:
return this.$autoNewLine || "\n"
}
}, this.$autoNewLine = "", this.$newLineMode = "auto", this.setNewLineMode = function(newLineMode) {
this.$newLineMode !== newLineMode && (this.$newLineMode = newLineMode, this._signal("changeNewLineMode"))
}, this.getNewLineMode = function() {
return this.$newLineMode
}, this.isNewLine = function(text) {
return "\r\n" == text || "\r" == text || "\n" == text
}, this.getLine = function(row) {
return this.$lines[row] || ""
}, this.getLines = function(firstRow, lastRow) {
return this.$lines.slice(firstRow, lastRow + 1)
}, this.getAllLines = function() {
return this.getLines(0, this.getLength())
}, this.getLength = function() {
return this.$lines.length
}, this.getTextRange = function(range) {
return this.getLinesForRange(range).join(this.getNewLineCharacter())
}, this.getLinesForRange = function(range) {
var lines;
if (range.start.row === range.end.row) lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
else {
lines = this.getLines(range.start.row, range.end.row), lines[0] = (lines[0] || "").substring(range.start.column);
var l = lines.length - 1;
range.end.row - range.start.row == l && (lines[l] = lines[l].substring(0, range.end.column))
}
return lines
}, this.insertLines = function(row, lines) {
return console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead."), this.insertFullLines(row, lines)
}, this.removeLines = function(firstRow, lastRow) {
return console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead."), this.removeFullLines(firstRow, lastRow)
}, this.insertNewLine = function(position) {
return console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, ['', '']) instead."), this.insertMergedLines(position, ["", ""])
}, this.insert = function(position, text) {
return 1 >= this.getLength() && this.$detectNewLine(text), this.insertMergedLines(position, this.$split(text))
}, this.insertInLine = function(position, text) {
var start = this.clippedPos(position.row, position.column),
end = this.pos(position.row, position.column + text.length);
return this.applyDelta({
start: start,
end: end,
action: "insert",
lines: [text]
}, !0), this.clonePos(end)
}, this.clippedPos = function(row, column) {
var length = this.getLength();
void 0 === row ? row = length : 0 > row ? row = 0 : row >= length && (row = length - 1, column = void 0);
var line = this.getLine(row);
return void 0 == column && (column = line.length), column = Math.min(Math.max(column, 0), line.length), {
row: row,
column: column
}
}, this.clonePos = function(pos) {
return {
row: pos.row,
column: pos.column
}
}, this.pos = function(row, column) {
return {
row: row,
column: column
}
}, this.$clipPosition = function(position) {
var length = this.getLength();
return position.row >= length ? (position.row = Math.max(0, length - 1), position.column = this.getLine(length - 1).length) : (position.row = Math.max(0, position.row), position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length)), position
}, this.insertFullLines = function(row, lines) {
row = Math.min(Math.max(row, 0), this.getLength());
var column = 0;
this.getLength() > row ? (lines = lines.concat([""]), column = 0) : (lines = [""].concat(lines), row--, column = this.$lines[row].length), this.insertMergedLines({
row: row,
column: column
}, lines)
}, this.insertMergedLines = function(position, lines) {
var start = this.clippedPos(position.row, position.column),
end = {
row: start.row + lines.length - 1,
column: (1 == lines.length ? start.column : 0) + lines[lines.length - 1].length
};
return this.applyDelta({
start: start,
end: end,
action: "insert",
lines: lines
}), this.clonePos(end)
}, this.remove = function(range) {
var start = this.clippedPos(range.start.row, range.start.column),
end = this.clippedPos(range.end.row, range.end.column);
return this.applyDelta({
start: start,
end: end,
action: "remove",
lines: this.getLinesForRange({
start: start,
end: end
})
}), this.clonePos(start)
}, this.removeInLine = function(row, startColumn, endColumn) {
var start = this.clippedPos(row, startColumn),
end = this.clippedPos(row, endColumn);
return this.applyDelta({
start: start,
end: end,
action: "remove",
lines: this.getLinesForRange({
start: start,
end: end
})
}, !0), this.clonePos(start)
}, this.removeFullLines = function(firstRow, lastRow) {
firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1), lastRow = Math.min(Math.max(0, lastRow), this.getLength() - 1);
var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0,
deleteLastNewLine = this.getLength() - 1 > lastRow,
startRow = deleteFirstNewLine ? firstRow - 1 : firstRow,
startCol = deleteFirstNewLine ? this.getLine(startRow).length : 0,
endRow = deleteLastNewLine ? lastRow + 1 : lastRow,
endCol = deleteLastNewLine ? 0 : this.getLine(endRow).length,
range = new Range(startRow, startCol, endRow, endCol),
deletedLines = this.$lines.slice(firstRow, lastRow + 1);
return this.applyDelta({
start: range.start,
end: range.end,
action: "remove",
lines: this.getLinesForRange(range)
}), deletedLines
}, this.removeNewLine = function(row) {
this.getLength() - 1 > row && row >= 0 && this.applyDelta({
start: this.pos(row, this.getLine(row).length),
end: this.pos(row + 1, 0),
action: "remove",
lines: ["", ""]
})
}, this.replace = function(range, text) {
if (range instanceof Range || (range = Range.fromPoints(range.start, range.end)), 0 === text.length && range.isEmpty()) return range.start;
if (text == this.getTextRange(range)) return range.end;
this.remove(range);
var end;
return end = text ? this.insert(range.start, text) : range.start
}, this.applyDeltas = function(deltas) {
for (var i = 0; deltas.length > i; i++) this.applyDelta(deltas[i])
}, this.revertDeltas = function(deltas) {
for (var i = deltas.length - 1; i >= 0; i--) this.revertDelta(deltas[i])
}, this.applyDelta = function(delta, doNotValidate) {
var isInsert = "insert" == delta.action;
(isInsert ? 1 >= delta.lines.length && !delta.lines[0] : !Range.comparePoints(delta.start, delta.end)) || (isInsert && delta.lines.length > 2e4 && this.$splitAndapplyLargeDelta(delta, 2e4), applyDelta(this.$lines, delta, doNotValidate), this._signal("change", delta))
}, this.$splitAndapplyLargeDelta = function(delta, MAX) {
for (var lines = delta.lines, l = lines.length, row = delta.start.row, column = delta.start.column, from = 0, to = 0;;) {
from = to, to += MAX - 1;
var chunk = lines.slice(from, to);
if (to > l) {
delta.lines = chunk, delta.start.row = row + from, delta.start.column = column;
break
}
chunk.push(""), this.applyDelta({
start: this.pos(row + from, column),
end: this.pos(row + to, column = 0),
action: delta.action,
lines: chunk
}, !0)
}
}, this.revertDelta = function(delta) {
this.applyDelta({
start: this.clonePos(delta.start),
end: this.clonePos(delta.end),
action: "insert" == delta.action ? "remove" : "insert",
lines: delta.lines.slice()
})
}, this.indexToPosition = function(index, startRow) {
for (var lines = this.$lines || this.getAllLines(), newlineLength = this.getNewLineCharacter().length, i = startRow || 0, l = lines.length; l > i; i++)
if (index -= lines[i].length + newlineLength, 0 > index) return {
row: i,
column: index + lines[i].length + newlineLength
};
return {
row: l - 1,
column: lines[l - 1].length
}
}, this.positionToIndex = function(pos, startRow) {
for (var lines = this.$lines || this.getAllLines(), newlineLength = this.getNewLineCharacter().length, index = 0, row = Math.min(pos.row, lines.length), i = startRow || 0; row > i; ++i) index += lines[i].length + newlineLength;
return index + pos.column
}