Merge pull request #1140 from ajaxorg/hotfix/renderer
Fix bug in rowCache
This commit is contained in:
commit
f3d0096050
4 changed files with 52 additions and 13 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,7 @@ var EditSession = function(text, mode) {
|
||||||
foldStart = foldLine ? foldLine.start.row : Infinity;
|
foldStart = foldLine ? foldLine.start.row : Infinity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doCache) {
|
if (doCache) {
|
||||||
this.$docRowCache.push(docRow);
|
this.$docRowCache.push(docRow);
|
||||||
this.$screenRowCache.push(row);
|
this.$screenRowCache.push(row);
|
||||||
|
|
@ -2269,12 +2271,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);
|
||||||
|
|
|
||||||
|
|
@ -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]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,11 @@ var ScrollBar = function(parent) {
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
this.onScroll = function() {
|
this.onScroll = function() {
|
||||||
this._emit("scroll", {data: this.element.scrollTop});
|
if (!this.skipEvent) {
|
||||||
|
this.scrollTop = this.element.scrollTop;
|
||||||
|
this._emit("scroll", {data: this.scrollTop});
|
||||||
|
}
|
||||||
|
this.skipEvent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -120,7 +124,7 @@ var ScrollBar = function(parent) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// TODO: on chrome 17+ for small zoom levels after calling this function
|
// on chrome 17+ for small zoom levels after calling this function
|
||||||
// this.element.scrollTop != scrollTop which makes page to scroll up.
|
// this.element.scrollTop != scrollTop which makes page to scroll up.
|
||||||
/**
|
/**
|
||||||
* Sets the scroll top of the scroll bar.
|
* Sets the scroll top of the scroll bar.
|
||||||
|
|
@ -130,7 +134,10 @@ var ScrollBar = function(parent) {
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
this.setScrollTop = function(scrollTop) {
|
this.setScrollTop = function(scrollTop) {
|
||||||
this.element.scrollTop = scrollTop;
|
if (this.scrollTop != scrollTop) {
|
||||||
|
this.skipEvent = true;
|
||||||
|
this.scrollTop = this.element.scrollTop = scrollTop;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(ScrollBar.prototype);
|
}).call(ScrollBar.prototype);
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ var VirtualRenderer = function(container, theme) {
|
||||||
|
|
||||||
this.setHighlightGutterLine(true);
|
this.setHighlightGutterLine(true);
|
||||||
this.$gutterLayer = new GutterLayer(this.$gutter);
|
this.$gutterLayer = new GutterLayer(this.$gutter);
|
||||||
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
|
this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
|
||||||
|
|
||||||
this.$markerBack = new MarkerLayer(this.content);
|
this.$markerBack = new MarkerLayer(this.content);
|
||||||
|
|
||||||
|
|
@ -239,7 +239,10 @@ var VirtualRenderer = function(container, theme) {
|
||||||
if (this.$changedLines.lastRow < lastRow)
|
if (this.$changedLines.lastRow < lastRow)
|
||||||
this.$changedLines.lastRow = lastRow;
|
this.$changedLines.lastRow = lastRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.$changedLines.firstRow > this.layerConfig.lastRow ||
|
||||||
|
this.$changedLines.lastRow < this.layerConfig.firstRow)
|
||||||
|
return;
|
||||||
this.$loop.schedule(this.CHANGE_LINES);
|
this.$loop.schedule(this.CHANGE_LINES);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -336,6 +339,16 @@ var VirtualRenderer = function(container, theme) {
|
||||||
delete this.resizing;
|
delete this.resizing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.onGutterResize = function() {
|
||||||
|
var width = this.$size.width;
|
||||||
|
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
|
||||||
|
this.scroller.style.left = gutterWidth + "px";
|
||||||
|
this.$size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth());
|
||||||
|
|
||||||
|
if (this.session.getUseWrapMode() && this.adjustWrapLimit())
|
||||||
|
this.$loop.schedule(this.CHANGE_FULL);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen.
|
* Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue