Bring back insertInLine
Avoids an extra $split call.
This commit is contained in:
parent
f2a2e4e1a8
commit
3a048cdf61
4 changed files with 37 additions and 8 deletions
|
|
@ -277,10 +277,6 @@ var Document = function(textOrLines) {
|
|||
console.warn('Use of document.insertNewLine is deprecated. Use insertMergedLines(position, [\'\', \'\']) instead.');
|
||||
return this.insertMergedLines(position, ['', '']);
|
||||
};
|
||||
this.insertInLine = function(position, text) {
|
||||
console.warn('Use of document.insertInLine is deprecated. Use insert instead.');
|
||||
return this.insert(position, text);
|
||||
};
|
||||
|
||||
/**
|
||||
* Inserts a block of `text` at the indicated `position`.
|
||||
|
|
@ -298,6 +294,39 @@ var Document = function(textOrLines) {
|
|||
return this.insertMergedLines(position, this.$split(text));
|
||||
};
|
||||
|
||||
/**
|
||||
* Inserts `text` into the `position` at the current row. This method also triggers the `'change'` event.
|
||||
*
|
||||
* This differs from the `insert` method in two ways:
|
||||
* 1. This does NOT handle newline characters (single-line text only).
|
||||
* 2. This is faster than the `insert` method for single-line text insertions.
|
||||
*
|
||||
* @param {Object} position The position to insert at; it's an object that looks like `{ row: row, column: column}`
|
||||
* @param {String} text A chunk of text
|
||||
* @returns {Object} Returns an object containing the final row and column, like this:
|
||||
* ```
|
||||
* {row: endRow, column: 0}
|
||||
* ```
|
||||
**/
|
||||
this.insertInLine = function(position, text) {
|
||||
|
||||
// Calculate insertion range end point.
|
||||
this.$clipPosition(position);
|
||||
var endPoint = {
|
||||
row : position.row,
|
||||
column : position.column + text.length
|
||||
};
|
||||
|
||||
// Apply delta (emits change).
|
||||
this.applyDelta({
|
||||
action: "insert",
|
||||
range: Range.fromPoints(position, endPoint),
|
||||
lines: [text]
|
||||
});
|
||||
|
||||
return endPoint;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fires whenever the document changes.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ var ElasticTabstopsLite = function(editor) {
|
|||
if (difference > 0) {
|
||||
// put the spaces after the tab and then delete the tab, so any insertion
|
||||
// points behave as expected
|
||||
this.$editor.session.getDocument().insert({row: row, column: it + 1}, Array(difference + 1).join(" ") + "\t");
|
||||
this.$editor.session.getDocument().insertInLine({row: row, column: it + 1}, Array(difference + 1).join(" ") + "\t");
|
||||
this.$editor.session.getDocument().removeInLine(row, it, it + 1);
|
||||
|
||||
bias += difference;
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ exports.convertIndentation = function(session, ch, len) {
|
|||
|
||||
if (toInsert != match) {
|
||||
doc.removeInLine(i, 0, match.length);
|
||||
doc.insert({row: i, column: 0}, toInsert);
|
||||
doc.insertInLine({row: i, column: 0}, toInsert);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,8 +92,8 @@ var Mode = function() {
|
|||
if (testRemove(line, i))
|
||||
return;
|
||||
if (!ignoreBlankLines || /\S/.test(line)) {
|
||||
doc.insert({row: i, column: line.length}, lineCommentEnd);
|
||||
doc.insert({row: i, column: minIndent}, lineCommentStart);
|
||||
doc.insertInLine({row: i, column: line.length}, lineCommentEnd);
|
||||
doc.insertInLine({row: i, column: minIndent}, lineCommentStart);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue