fix scrolling animation

This commit is contained in:
nightwing 2012-04-25 11:26:15 +04:00
commit 7bff33c986

View file

@ -751,22 +751,22 @@ var VirtualRenderer = function(container, theme) {
return steps; return steps;
}; };
this.scrollToLine = function(line, center, animate) { this.scrollToLine = function(line, center, animate, callback) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
var offset = pos.top; var offset = pos.top;
if (center) if (center)
offset -= this.$size.scrollerHeight / 2; offset -= this.$size.scrollerHeight / 2;
if (animate) { if (animate !== false) {
this.animateScrolling(function() { this.animateScrolling(function() {
this.session.setScrollTop(offset); this.session.setScrollTop(offset);
}, this); }, this, callback);
} else { } else {
this.session.setScrollTop(offset); this.session.setScrollTop(offset);
} }
}; };
this.animateScrolling = function(scrollFunc, self) { this.animateScrolling = function(scrollFunc, self, callback) {
var fromValue = this.scrollTop; var fromValue = this.scrollTop;
scrollFunc.call(self); scrollFunc.call(self);
var toValue = this.scrollTop; var toValue = this.scrollTop;
@ -778,7 +778,7 @@ var VirtualRenderer = function(container, theme) {
clearInterval(this.$timer); clearInterval(this.$timer);
_self.session.setScrollTop(steps.shift()); _self.session.setScrollTop(steps.shift());
this.$timer = setInterval(function() { this.$timer = setInterval(function() {
if (steps.length) { if (steps.length) {
_self.session.setScrollTop(steps.shift()); _self.session.setScrollTop(steps.shift());
// trick session to think it's already scrolled to not loose toValue // trick session to think it's already scrolled to not loose toValue
@ -789,6 +789,7 @@ var VirtualRenderer = function(container, theme) {
_self.session.$scrollTop = -1; _self.session.$scrollTop = -1;
_self.session.setScrollTop(toValue); _self.session.setScrollTop(toValue);
callback && callback();
} }
}, 10); }, 10);
} }