simplify animateScroll a little

This commit is contained in:
nightwing 2012-04-26 10:27:02 +04:00
commit fb2be29d5e
2 changed files with 35 additions and 38 deletions

View file

@ -979,11 +979,13 @@ var Editor = function(renderer, session) {
}
this.$blockScrolling--;
this.renderer.animateScrolling(function() {
renderer.scrollBy(0, rows * config.lineHeight);
if (select != null)
renderer.scrollCursorIntoView(null, 0.5);
}, this);
var scrollTop = renderer.scrollTop;
renderer.scrollBy(0, rows * config.lineHeight);
if (select != null)
renderer.scrollCursorIntoView(null, 0.5);
renderer.animateScrolling(scrollTop);
};
this.selectPageDown = function() {
@ -1141,17 +1143,17 @@ var Editor = function(renderer, session) {
};
this.navigateFileEnd = function() {
this.renderer.animateScrolling(function() {
this.selection.moveCursorFileEnd();
this.clearSelection();
}, this);
var scrollTop = this.renderer.scrollTop;
this.selection.moveCursorFileEnd();
this.clearSelection();
this.renderer.animateScrolling(scrollTop);
};
this.navigateFileStart = function() {
this.renderer.animateScrolling(function() {
this.selection.moveCursorFileStart();
this.clearSelection();
}, this);
var scrollTop = this.renderer.scrollTop;
this.selection.moveCursorFileStart();
this.clearSelection();
this.renderer.animateScrolling(scrollTop);
};
this.navigateWordRight = function() {
@ -1261,9 +1263,9 @@ var Editor = function(renderer, session) {
this.selection.setSelectionRange(range);
this.$blockScrolling -= 1;
this.renderer.animateScrolling(function() {
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
}, this);
var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
this.renderer.animateScrolling(scrollTop);
}
};

View file

@ -757,18 +757,13 @@ var VirtualRenderer = function(container, theme) {
if (center)
offset -= this.$size.scrollerHeight / 2;
if (animate !== false) {
this.animateScrolling(function() {
this.session.setScrollTop(offset);
}, this, callback);
} else {
this.session.setScrollTop(offset);
}
var initialScroll = this.scrollTop;
this.session.setScrollTop(offset);
if (animate !== false)
this.animateScrolling(initialScroll, callback);
};
this.animateScrolling = function(scrollFunc, self, callback) {
var fromValue = this.scrollTop;
scrollFunc.call(self);
this.animateScrolling = function(fromValue, callback) {
var toValue = this.scrollTop;
if (this.$animatedScroll && Math.abs(fromValue - toValue) < 100000) {
var _self = this;