diff --git a/lib/ace/document.js b/lib/ace/document.js index de77582e..6968e8f0 100644 --- a/lib/ace/document.js +++ b/lib/ace/document.js @@ -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. * diff --git a/lib/ace/ext/elastic_tabstops_lite.js b/lib/ace/ext/elastic_tabstops_lite.js index a8c3570c..9901c5df 100644 --- a/lib/ace/ext/elastic_tabstops_lite.js +++ b/lib/ace/ext/elastic_tabstops_lite.js @@ -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; diff --git a/lib/ace/ext/whitespace.js b/lib/ace/ext/whitespace.js index be0cde28..83486fb0 100644 --- a/lib/ace/ext/whitespace.js +++ b/lib/ace/ext/whitespace.js @@ -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); } } } diff --git a/lib/ace/mode/text.js b/lib/ace/mode/text.js index 76ba15b5..343fc271 100644 --- a/lib/ace/mode/text.js +++ b/lib/ace/mode/text.js @@ -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); } };