Skip to content

Commit f3d0096

Browse files
author
Mostafa Eweda
committed
Merge pull request ajaxorg#1140 from ajaxorg/hotfix/renderer
Fix bug in rowCache
2 parents e44f9c1 + 71b54a5 commit f3d0096

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

lib/ace/edit_session.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ var EditSession = function(text, mode) {
244244
return mid;
245245
}
246246

247-
return low && low -1;
247+
return low -1;
248248
};
249249

250250
this.resetCaches = function() {
@@ -2164,12 +2164,13 @@ var EditSession = function(text, mode) {
21642164

21652165
var rowCache = this.$screenRowCache;
21662166
var i = this.$getRowCacheIndex(rowCache, screenRow);
2167-
if (0 < i && i < rowCache.length) {
2167+
var l = rowCache.length;
2168+
if (l && i >= 0) {
21682169
var row = rowCache[i];
21692170
var docRow = this.$docRowCache[i];
2170-
var doCache = screenRow > row || (screenRow == row && i == rowCache.length - 1);
2171+
var doCache = screenRow > rowCache[l - 1];
21712172
} else {
2172-
var doCache = i != 0 || !rowCache.length;
2173+
var doCache = !l;
21732174
}
21742175

21752176
var maxRow = this.getLength() - 1;
@@ -2189,6 +2190,7 @@ var EditSession = function(text, mode) {
21892190
foldStart = foldLine ? foldLine.start.row : Infinity;
21902191
}
21912192
}
2193+
21922194
if (doCache) {
21932195
this.$docRowCache.push(docRow);
21942196
this.$screenRowCache.push(row);
@@ -2269,12 +2271,13 @@ var EditSession = function(text, mode) {
22692271

22702272
var rowCache = this.$docRowCache;
22712273
var i = this.$getRowCacheIndex(rowCache, docRow);
2272-
if (0 < i && i < rowCache.length) {
2274+
var l = rowCache.length;
2275+
if (l && i >= 0) {
22732276
var row = rowCache[i];
22742277
var screenRow = this.$screenRowCache[i];
2275-
var doCache = docRow > row || (docRow == row && i == rowCache.length - 1);
2278+
var doCache = docRow > rowCache[l - 1];
22762279
} else {
2277-
var doCache = i != 0 || !rowCache.length;
2280+
var doCache = !l;
22782281
}
22792282

22802283
var foldLine = this.getNextFoldLine(row);

lib/ace/edit_session_test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function createFoldTestSession() {
6262
}
6363

6464
function assertArray(a, b) {
65+
assert.equal(a+"", b+"");
6566
assert.ok(a.length == b.length);
6667
for (var i = 0; i < a.length; i++) {
6768
assert.equal(a[i], b[i]);
@@ -980,7 +981,8 @@ module.exports = {
980981
assertArray(session.$docRowCache, [1,3,4]);
981982
assertArray(session.$screenRowCache, [1,2,3]);
982983

983-
session.screenToDocumentPosition(0,0);
984+
var pos = session.screenToDocumentPosition(0,0);
985+
assert.equal(pos.row, 0);
984986
assertArray(session.$docRowCache, [1,3,4]);
985987
assertArray(session.$screenRowCache, [1,2,3]);
986988

@@ -991,6 +993,20 @@ module.exports = {
991993
session.$resetRowCache();
992994
assertArray(session.$docRowCache, []);
993995
assertArray(session.$screenRowCache, []);
996+
997+
session.screenToDocumentPosition(1,3);
998+
assertArray(session.$docRowCache, [1]);
999+
assertArray(session.$screenRowCache, [1]);
1000+
1001+
session.screenToDocumentPosition(5,3);
1002+
assertArray(session.$docRowCache, [1,3,4]);
1003+
assertArray(session.$screenRowCache, [1,2,3]);
1004+
1005+
session = new EditSession(new Array(30).join("\n"));
1006+
session.documentToScreenPosition(2,0);
1007+
session.documentToScreenPosition(2,0);
1008+
assertArray(session.$docRowCache, [1,2]);
1009+
assertArray(session.$screenRowCache, [1,2]);
9941010
}
9951011
};
9961012

lib/ace/scrollbar.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ var ScrollBar = function(parent) {
8585
*
8686
**/
8787
this.onScroll = function() {
88-
this._emit("scroll", {data: this.element.scrollTop});
88+
if (!this.skipEvent) {
89+
this.scrollTop = this.element.scrollTop;
90+
this._emit("scroll", {data: this.scrollTop});
91+
}
92+
this.skipEvent = false;
8993
};
9094

9195
/**
@@ -120,7 +124,7 @@ var ScrollBar = function(parent) {
120124
};
121125

122126

123-
// TODO: on chrome 17+ for small zoom levels after calling this function
127+
// on chrome 17+ for small zoom levels after calling this function
124128
// this.element.scrollTop != scrollTop which makes page to scroll up.
125129
/**
126130
* Sets the scroll top of the scroll bar.
@@ -130,7 +134,10 @@ var ScrollBar = function(parent) {
130134
*
131135
**/
132136
this.setScrollTop = function(scrollTop) {
133-
this.element.scrollTop = scrollTop;
137+
if (this.scrollTop != scrollTop) {
138+
this.skipEvent = true;
139+
this.scrollTop = this.element.scrollTop = scrollTop;
140+
}
134141
};
135142

136143
}).call(ScrollBar.prototype);

lib/ace/virtual_renderer.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var VirtualRenderer = function(container, theme) {
9696

9797
this.setHighlightGutterLine(true);
9898
this.$gutterLayer = new GutterLayer(this.$gutter);
99-
this.$gutterLayer.on("changeGutterWidth", this.onResize.bind(this, true));
99+
this.$gutterLayer.on("changeGutterWidth", this.onGutterResize.bind(this));
100100

101101
this.$markerBack = new MarkerLayer(this.content);
102102

@@ -239,7 +239,10 @@ var VirtualRenderer = function(container, theme) {
239239
if (this.$changedLines.lastRow < lastRow)
240240
this.$changedLines.lastRow = lastRow;
241241
}
242-
242+
243+
if (this.$changedLines.firstRow > this.layerConfig.lastRow ||
244+
this.$changedLines.lastRow < this.layerConfig.firstRow)
245+
return;
243246
this.$loop.schedule(this.CHANGE_LINES);
244247
};
245248

@@ -336,6 +339,16 @@ var VirtualRenderer = function(container, theme) {
336339
delete this.resizing;
337340
};
338341

342+
this.onGutterResize = function() {
343+
var width = this.$size.width;
344+
var gutterWidth = this.showGutter ? this.$gutter.offsetWidth : 0;
345+
this.scroller.style.left = gutterWidth + "px";
346+
this.$size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBar.getWidth());
347+
348+
if (this.session.getUseWrapMode() && this.adjustWrapLimit())
349+
this.$loop.schedule(this.CHANGE_FULL);
350+
};
351+
339352
/**
340353
*
341354
* Adjusts the wrap limit, which is the number of characters that can fit within the width of the edit area on screen.

0 commit comments

Comments
 (0)