diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index b263d1d2..279519f8 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -883,6 +883,8 @@ var EditSession = function(text, mode) { // TODO: Update row data on folds. var foldLines = this.$foldData; + + for (var i = 0; i < foldLines.length; i++) { var foldLine = foldLines[i]; if (foldLine.start.row >= firstRow + len) { @@ -900,8 +902,6 @@ var EditSession = function(text, mode) { } // TODO: Expand folds here if needed. - // TODO: Split foldLine in case there are new lines added in - // between of a foldLine. // If some new line is added inside of a foldLine, then split // the fold line up. @@ -1569,37 +1569,6 @@ var EditSession = function(text, mode) { return null; } - this.getStringAt = function(session, row, column, trim) { - var fold, lastFold, cmp, str; - lastFold = { - end: { column: 0 } - }; - // TODO: Refactor to use getNextFoldTo function. - for (var i = 0; i < this.folds.length; i++) { - fold = this.folds[i]; - cmp = fold.range.compareEnd(row, column); - if (cmp == -1) { - str = session.getLine(fold.start.row). - substring(lastFold.end.column, fold.start.column); - break; - } else if (cmp == 0) { - return null; - } - lastFold = fold; - } - if (!str) { - str = session.getLine(fold.start.row). - substring(lastFold.end.column); - } - if (trim == -1) { - return str.substring(0, column - lastFold.end.column); - } else if (trim == 1) { - return str.substring(column - lastFold.end.column) - } else { - return str; - } - } - this.addRemoveChars = function(row, column, len) { var ret = this.getNextFoldTo(row, column), fold, folds; @@ -1691,12 +1660,39 @@ var EditSession = function(text, mode) { * foobarwol|rd -trim=+1> "rld" * fo|obarwolrd -trim=00> "foo" */ - this.getFoldStringAt = function(row, column, trim) { - var foldLine = this.getFoldLine(row); + this.getFoldStringAt = function(row, column, trim, foldLine) { + var foldLine = foldLine || this.getFoldLine(row); if (!foldLine) { return null; } else { - return foldLine.getStringAt(this, row, column, trim); + var fold, lastFold, cmp, str; + lastFold = { + end: { column: 0 } + }; + // TODO: Refactor to use getNextFoldTo function. + for (var i = 0; i < foldLine.folds.length; i++) { + fold = foldLine.folds[i]; + cmp = fold.range.compareEnd(row, column); + if (cmp == -1) { + str = this.getLine(fold.start.row). + substring(lastFold.end.column, fold.start.column); + break; + } else if (cmp == 0) { + return null; + } + lastFold = fold; + } + if (!str) { + str = this.getLine(fold.start.row). + substring(lastFold.end.column); + } + if (trim == -1) { + return str.substring(0, column - lastFold.end.column); + } else if (trim == 1) { + return str.substring(column - lastFold.end.column) + } else { + return str; + } } } diff --git a/lib/ace/selection.js b/lib/ace/selection.js index 70a5fafe..e711c514 100644 --- a/lib/ace/selection.js +++ b/lib/ace/selection.js @@ -382,11 +382,7 @@ var Selection = function(session) { return; } - var str = null; - var foldLine = this.session.getFoldLine(row); - if (foldLine) { - str = foldLine.getStringAt(this.session, row, column, -1); - } + var str = this.session.getFoldStringAt(row, column, -1); if (str == null) { str = this.doc.getLine(row).substring(0, column) }