diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 8f772db7..cc7d72b0 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -1556,10 +1556,7 @@ var EditSession = function(text, mode) { // If wrapMode is activaed, the wrapData array has to be initialized. if (useWrapMode) { var len = this.getLength(); - this.$wrapData = []; - for (var i = 0; i < len; i++) { - this.$wrapData.push([]); - } + this.$wrapData = Array(len); this.$updateWrapData(0, len - 1); } @@ -1719,16 +1716,10 @@ var EditSession = function(text, mode) { lastRow = firstRow; } else { - var args; - if (useWrapMode) { - args = [firstRow, 0]; - for (var i = 0; i < len; i++) args.push([]); - this.$wrapData.splice.apply(this.$wrapData, args); - } else { - args = Array(len); - args.unshift(firstRow, 0); - this.$rowLengthCache.splice.apply(this.$rowLengthCache, args); - } + var args = Array(len); + args.unshift(firstRow, 0); + var arr = useWrapMode ? this.$wrapData : this.$rowLengthCache + arr.splice.apply(arr, args); // If some new line is added inside of a foldLine, then split // the fold line up. @@ -1833,8 +1824,7 @@ var EditSession = function(text, mode) { lines[foldLine.end.row].length + 1 ); - wrapData[foldLine.start.row] - = this.$computeWrapSplits(tokens, wrapLimit, tabSize); + wrapData[foldLine.start.row] = this.$computeWrapSplits(tokens, wrapLimit, tabSize); row = foldLine.end.row + 1; } } @@ -2023,9 +2013,6 @@ var EditSession = function(text, mode) { * The first position indicates the number of columns for `str` on screen.
* The second value contains the position of the document column that this function read until. * - * - * - * **/ this.$getStringScreenWidth = function(str, maxScreenColumn, screenColumn) { if (maxScreenColumn == 0) @@ -2326,14 +2313,16 @@ var EditSession = function(text, mode) { // Clamp textLine if in wrapMode. if (this.$useWrapMode) { var wrapRow = this.$wrapData[foldStartRow]; - var screenRowOffset = 0; - while (textLine.length >= wrapRow[screenRowOffset]) { - screenRow ++; - screenRowOffset++; + if (wrapRow) { + var screenRowOffset = 0; + while (textLine.length >= wrapRow[screenRowOffset]) { + screenRow ++; + screenRowOffset++; + } + textLine = textLine.substring( + wrapRow[screenRowOffset - 1] || 0, textLine.length + ); } - textLine = textLine.substring( - wrapRow[screenRowOffset - 1] || 0, textLine.length - ); } return { @@ -2387,7 +2376,8 @@ var EditSession = function(text, mode) { var foldStart = fold ? fold.start.row :Infinity; while (row < lastRow) { - screenRows += this.$wrapData[row].length + 1; + var splits = this.$wrapData[row]; + screenRows += splits ? splits.length + 1 : 1; row ++; if (row > foldStart) { row = fold.end.row+1;