fix bug in rowCache
This commit is contained in:
parent
34ce33b4cc
commit
fd126e06c3
2 changed files with 29 additions and 8 deletions
|
|
@ -244,7 +244,7 @@ var EditSession = function(text, mode) {
|
||||||
return mid;
|
return mid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return low && low -1;
|
return low -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.resetCaches = function() {
|
this.resetCaches = function() {
|
||||||
|
|
@ -2164,12 +2164,13 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
var rowCache = this.$screenRowCache;
|
var rowCache = this.$screenRowCache;
|
||||||
var i = this.$getRowCacheIndex(rowCache, screenRow);
|
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 row = rowCache[i];
|
||||||
var docRow = this.$docRowCache[i];
|
var docRow = this.$docRowCache[i];
|
||||||
var doCache = screenRow > row || (screenRow == row && i == rowCache.length - 1);
|
var doCache = screenRow > rowCache[l - 1];
|
||||||
} else {
|
} else {
|
||||||
var doCache = i != 0 || !rowCache.length;
|
var doCache = !l;
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxRow = this.getLength() - 1;
|
var maxRow = this.getLength() - 1;
|
||||||
|
|
@ -2189,6 +2190,8 @@ var EditSession = function(text, mode) {
|
||||||
foldStart = foldLine ? foldLine.start.row : Infinity;
|
foldStart = foldLine ? foldLine.start.row : Infinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (rowCache[rowCache.length-1] >= row)console.error("---------")
|
||||||
if (doCache) {
|
if (doCache) {
|
||||||
this.$docRowCache.push(docRow);
|
this.$docRowCache.push(docRow);
|
||||||
this.$screenRowCache.push(row);
|
this.$screenRowCache.push(row);
|
||||||
|
|
@ -2269,12 +2272,13 @@ var EditSession = function(text, mode) {
|
||||||
|
|
||||||
var rowCache = this.$docRowCache;
|
var rowCache = this.$docRowCache;
|
||||||
var i = this.$getRowCacheIndex(rowCache, docRow);
|
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 row = rowCache[i];
|
||||||
var screenRow = this.$screenRowCache[i];
|
var screenRow = this.$screenRowCache[i];
|
||||||
var doCache = docRow > row || (docRow == row && i == rowCache.length - 1);
|
var doCache = docRow > rowCache[l - 1];
|
||||||
} else {
|
} else {
|
||||||
var doCache = i != 0 || !rowCache.length;
|
var doCache = !l;
|
||||||
}
|
}
|
||||||
|
|
||||||
var foldLine = this.getNextFoldLine(row);
|
var foldLine = this.getNextFoldLine(row);
|
||||||
|
|
@ -2295,6 +2299,7 @@ var EditSession = function(text, mode) {
|
||||||
screenRow += this.getRowLength(row);
|
screenRow += this.getRowLength(row);
|
||||||
row = rowEnd;
|
row = rowEnd;
|
||||||
|
|
||||||
|
// if (rowCache[rowCache.length-1] >= row)console.error("---------")
|
||||||
if (doCache) {
|
if (doCache) {
|
||||||
this.$docRowCache.push(row);
|
this.$docRowCache.push(row);
|
||||||
this.$screenRowCache.push(screenRow);
|
this.$screenRowCache.push(screenRow);
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ function createFoldTestSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertArray(a, b) {
|
function assertArray(a, b) {
|
||||||
|
assert.equal(a+"", b+"");
|
||||||
assert.ok(a.length == b.length);
|
assert.ok(a.length == b.length);
|
||||||
for (var i = 0; i < a.length; i++) {
|
for (var i = 0; i < a.length; i++) {
|
||||||
assert.equal(a[i], b[i]);
|
assert.equal(a[i], b[i]);
|
||||||
|
|
@ -980,7 +981,8 @@ module.exports = {
|
||||||
assertArray(session.$docRowCache, [1,3,4]);
|
assertArray(session.$docRowCache, [1,3,4]);
|
||||||
assertArray(session.$screenRowCache, [1,2,3]);
|
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.$docRowCache, [1,3,4]);
|
||||||
assertArray(session.$screenRowCache, [1,2,3]);
|
assertArray(session.$screenRowCache, [1,2,3]);
|
||||||
|
|
||||||
|
|
@ -991,6 +993,20 @@ module.exports = {
|
||||||
session.$resetRowCache();
|
session.$resetRowCache();
|
||||||
assertArray(session.$docRowCache, []);
|
assertArray(session.$docRowCache, []);
|
||||||
assertArray(session.$screenRowCache, []);
|
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]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue