diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index 26159dff..6471d7c2 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -230,14 +230,14 @@ var EditSession = function(text, mode) { * * **/ - this.$resetRowCache = function(docRrow) { - if (!docRrow) { + this.$resetRowCache = function(docRow) { + if (!docRow) { this.$docRowCache = []; this.$screenRowCache = []; return; } - var i = this.$getRowCacheIndex(this.$docRowCache, docRrow) + 1; + var i = this.$getRowCacheIndex(this.$docRowCache, docRow) + 1; var l = this.$docRowCache.length; this.$docRowCache.splice(i, l); this.$screenRowCache.splice(i, l); @@ -1868,10 +1868,8 @@ var EditSession = function(text, mode) { }; this.$updateRowLengthCache = function(firstRow, lastRow, b) { - //console.log(firstRow, lastRow, b) this.$rowLengthCache[firstRow] = null; this.$rowLengthCache[lastRow] = null; - //console.log(this.$rowLengthCache) }; /** internal, hide @@ -2251,7 +2249,7 @@ var EditSession = function(text, mode) { var docRow = this.$docRowCache[i]; var doCache = screenRow > row || (screenRow == row && i == rowCache.length - 1); } else { - var doCache = true; + var doCache = i != 0 || !rowCache.length; } var maxRow = this.getLength() - 1; @@ -2356,7 +2354,7 @@ var EditSession = function(text, mode) { var screenRow = this.$screenRowCache[i]; var doCache = docRow > row || (docRow == row && i == rowCache.length - 1); } else { - var doCache = true; + var doCache = i != 0 || !rowCache.length; } var foldLine = this.getNextFoldLine(row); diff --git a/lib/ace/edit_session_test.js b/lib/ace/edit_session_test.js index 0f7edd9e..e62e2b3f 100644 --- a/lib/ace/edit_session_test.js +++ b/lib/ace/edit_session_test.js @@ -69,6 +69,13 @@ function createFoldTestSession() { return session; } +function assertArray(a, b) { + assert.ok(a.length == b.length); + for (var i = 0; i < a.length; i++) { + assert.equal(a[i], b[i]); + } +} + module.exports = { "test: find matching opening bracket in Text mode" : function() { @@ -808,13 +815,6 @@ module.exports = { }, "test fold wrap data compution": function() { - function assertArray(a, b) { - assert.ok(a.length == b.length); - for (var i = 0; i < a.length; i++) { - assert.equal(a[i], b[i]); - } - } - function assertWrap(line0, line1, line2) { line0 && assertArray(wrapData[0], line0); line1 && assertArray(wrapData[1], line1); @@ -971,6 +971,34 @@ module.exports = { session.addFold("fold0", new Range(0, 1, 0, 5)); session.addFold("fold0", new Range(0, 6, 0, 8)); assert.equal(fold.subFolds.length, 2); + }, + + "test row cache": function() { + var session = createFoldTestSession(); + + session.screenToDocumentPosition(2,3); + assertArray(session.$docRowCache, [1,3]); + assertArray(session.$screenRowCache, [1,2]); + + session.screenToDocumentPosition(5,3); + assertArray(session.$docRowCache, [1,3,4]); + assertArray(session.$screenRowCache, [1,2,3]); + + session.screenToDocumentPosition(0,3); + assertArray(session.$docRowCache, [1,3,4]); + assertArray(session.$screenRowCache, [1,2,3]); + + session.screenToDocumentPosition(0,0); + assertArray(session.$docRowCache, [1,3,4]); + assertArray(session.$screenRowCache, [1,2,3]); + + session.screenToDocumentPosition(1,0); + assertArray(session.$docRowCache, [1,3,4]); + assertArray(session.$screenRowCache, [1,2,3]); + + session.$resetRowCache(); + assertArray(session.$docRowCache, []); + assertArray(session.$screenRowCache, []); } };