Skip to content

Commit fa1a355

Browse files
committed
[simplescrollbar addon] Make sure bar position is clipped after update
Closes codemirror#3891
1 parent 1de61c6 commit fa1a355

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

addon/scroll/simplescrollbars.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@
5959
CodeMirror.on(this.node, "DOMMouseScroll", onWheel);
6060
}
6161

62-
Bar.prototype.moveTo = function(pos, update) {
62+
Bar.prototype.setPos = function(pos) {
6363
if (pos < 0) pos = 0;
6464
if (pos > this.total - this.screen) pos = this.total - this.screen;
65-
if (pos == this.pos) return;
65+
if (pos == this.pos) return false;
6666
this.pos = pos;
6767
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
6868
(pos * (this.size / this.total)) + "px";
69-
if (update !== false) this.scroll(pos, this.orientation);
69+
return true
7070
};
7171

72+
Bar.prototype.moveTo = function(pos) {
73+
if (this.setPos(pos)) this.scroll(pos, this.orientation);
74+
}
75+
7276
var minButtonSize = 10;
7377

7478
Bar.prototype.update = function(scrollSize, clientSize, barSize) {
@@ -83,8 +87,7 @@
8387
}
8488
this.inner.style[this.orientation == "horizontal" ? "width" : "height"] =
8589
buttonSize + "px";
86-
this.inner.style[this.orientation == "horizontal" ? "left" : "top"] =
87-
this.pos * (this.size / this.total) + "px";
90+
this.setPos(this.pos);
8891
};
8992

9093
function SimpleScrollbars(cls, place, scroll) {
@@ -111,7 +114,6 @@
111114
if (needsV) {
112115
this.vert.update(measure.scrollHeight, measure.clientHeight,
113116
measure.viewHeight - (needsH ? width : 0));
114-
this.vert.node.style.display = "block";
115117
this.vert.node.style.bottom = needsH ? width + "px" : "0";
116118
}
117119
if (needsH) {
@@ -125,11 +127,11 @@
125127
};
126128

127129
SimpleScrollbars.prototype.setScrollTop = function(pos) {
128-
this.vert.moveTo(pos, false);
130+
this.vert.setPos(pos);
129131
};
130132

131133
SimpleScrollbars.prototype.setScrollLeft = function(pos) {
132-
this.horiz.moveTo(pos, false);
134+
this.horiz.setPos(pos);
133135
};
134136

135137
SimpleScrollbars.prototype.clear = function() {

0 commit comments

Comments
 (0)