From fd126e06c363f64f5efb7095cada76a555fd7d5e Mon Sep 17 00:00:00 2001 From: nightwing Date: Sat, 1 Dec 2012 17:11:37 +0400 Subject: [PATCH] fix bug in rowCache --- lib/ace/edit_session.js | 19 ++++++++++++------- lib/ace/edit_session_test.js | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/ace/edit_session.js b/lib/ace/edit_session.js index bfa85335..2402a51c 100644 --- a/lib/ace/edit_session.js +++ b/lib/ace/edit_session.js @@ -244,7 +244,7 @@ var EditSession = function(text, mode) { return mid; } - return low && low -1; + return low -1; }; this.resetCaches = function() { @@ -2164,12 +2164,13 @@ var EditSession = function(text, mode) { var rowCache = this.$screenRowCache; var i = this.$getRowCacheIndex(rowCache, screenRow); - if (0 < i && i < rowCache.length) { + var l = rowCache.length; + if (l && i >= 0) { var row = rowCache[i]; var docRow = this.$docRowCache[i]; - var doCache = screenRow > row || (screenRow == row && i == rowCache.length - 1); + var doCache = screenRow > rowCache[l - 1]; } else { - var doCache = i != 0 || !rowCache.length; + var doCache = !l; } var maxRow = this.getLength() - 1; @@ -2189,6 +2190,8 @@ var EditSession = function(text, mode) { foldStart = foldLine ? foldLine.start.row : Infinity; } } + + // if (rowCache[rowCache.length-1] >= row)console.error("---------") if (doCache) { this.$docRowCache.push(docRow); this.$screenRowCache.push(row); @@ -2269,12 +2272,13 @@ var EditSession = function(text, mode) { var rowCache = this.$docRowCache; var i = this.$getRowCacheIndex(rowCache, docRow); - if (0 < i && i < rowCache.length) { + var l = rowCache.length; + if (l && i >= 0) { var row = rowCache[i]; var screenRow = this.$screenRowCache[i]; - var doCache = docRow > row || (docRow == row && i == rowCache.length - 1); + var doCache = docRow > rowCache[l - 1]; } else { - var doCache = i != 0 || !rowCache.length; + var doCache = !l; } var foldLine = this.getNextFoldLine(row); @@ -2295,6 +2299,7 @@ var EditSession = function(text, mode) { screenRow += this.getRowLength(row); row = rowEnd; + // if (rowCache[rowCache.length-1] >= row)console.error("---------") if (doCache) { this.$docRowCache.push(row); this.$screenRowCache.push(screenRow); diff --git a/lib/ace/edit_session_test.js b/lib/ace/edit_session_test.js index e89ad57f..07d6b375 100644 --- a/lib/ace/edit_session_test.js +++ b/lib/ace/edit_session_test.js @@ -62,6 +62,7 @@ function createFoldTestSession() { } function assertArray(a, b) { + assert.equal(a+"", b+""); assert.ok(a.length == b.length); for (var i = 0; i < a.length; i++) { assert.equal(a[i], b[i]); @@ -980,7 +981,8 @@ module.exports = { assertArray(session.$docRowCache, [1,3,4]); assertArray(session.$screenRowCache, [1,2,3]); - session.screenToDocumentPosition(0,0); + var pos = session.screenToDocumentPosition(0,0); + assert.equal(pos.row, 0); assertArray(session.$docRowCache, [1,3,4]); assertArray(session.$screenRowCache, [1,2,3]); @@ -991,6 +993,20 @@ module.exports = { session.$resetRowCache(); assertArray(session.$docRowCache, []); assertArray(session.$screenRowCache, []); + + session.screenToDocumentPosition(1,3); + assertArray(session.$docRowCache, [1]); + assertArray(session.$screenRowCache, [1]); + + session.screenToDocumentPosition(5,3); + assertArray(session.$docRowCache, [1,3,4]); + assertArray(session.$screenRowCache, [1,2,3]); + + session = new EditSession(new Array(30).join("\n")); + session.documentToScreenPosition(2,0); + session.documentToScreenPosition(2,0); + assertArray(session.$docRowCache, [1,2]); + assertArray(session.$screenRowCache, [1,2]); } };