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

@ -79,7 +79,7 @@ var Editor = function(renderer, session) {
this.$search = new Search().set({ this.$search = new Search().set({
wrap: true wrap: true
}); });
this.setSession(session || new EditSession("")); this.setSession(session || new EditSession(""));
}; };
@ -351,13 +351,13 @@ var Editor = function(renderer, session) {
} }
} }
}; };
this.$updateHighlightGutterLine = function(){ this.$updateHighlightGutterLine = function(){
if (typeof this.$lastrow == "number") if (typeof this.$lastrow == "number")
this.renderer.removeGutterDecoration(this.$lastrow, "ace_gutter_active_line"); this.renderer.removeGutterDecoration(this.$lastrow, "ace_gutter_active_line");
this.$lastrow = null; this.$lastrow = null;
if (this.$highlightGutterLine) if (this.$highlightGutterLine)
this.renderer.addGutterDecoration( this.renderer.addGutterDecoration(
this.$lastrow = this.getCursorPosition().row, "ace_gutter_active_line"); this.$lastrow = this.getCursorPosition().row, "ace_gutter_active_line");
@ -437,7 +437,7 @@ var Editor = function(renderer, session) {
this.onCut = function() { this.onCut = function() {
this.commands.exec("cut", this); this.commands.exec("cut", this);
}; };
this.onPaste = function(text) { this.onPaste = function(text) {
this._emit("paste", text); this._emit("paste", text);
this.insert(text); this.insert(text);
@ -586,7 +586,7 @@ var Editor = function(renderer, session) {
this.$highlightActiveLine = true; this.$highlightActiveLine = true;
this.setHighlightActiveLine = function(shouldHighlight) { this.setHighlightActiveLine = function(shouldHighlight) {
if (this.$highlightActiveLine == shouldHighlight) if (this.$highlightActiveLine == shouldHighlight)
return; return;
this.$highlightActiveLine = shouldHighlight; this.$highlightActiveLine = shouldHighlight;
@ -596,16 +596,16 @@ var Editor = function(renderer, session) {
this.getHighlightActiveLine = function() { this.getHighlightActiveLine = function() {
return this.$highlightActiveLine; return this.$highlightActiveLine;
}; };
this.$highlightGutterLine = true; this.$highlightGutterLine = true;
this.setHighlightGutterLine = function(shouldHighlightGutterLine) { this.setHighlightGutterLine = function(shouldHighlightGutterLine) {
if (this.$highlightGutterLine == shouldHighlightGutterLine) if (this.$highlightGutterLine == shouldHighlightGutterLine)
return; return;
this.$highlightGutterLine = shouldHighlightGutterLine; this.$highlightGutterLine = shouldHighlightGutterLine;
this.$updateHighlightGutterLine(); this.$updateHighlightGutterLine();
}; };
this.getHighlightGutterLine = function() { this.getHighlightGutterLine = function() {
return this.$highlightGutterLine; return this.$highlightGutterLine;
}; };
@ -979,11 +979,13 @@ var Editor = function(renderer, session) {
} }
this.$blockScrolling--; this.$blockScrolling--;
this.renderer.animateScrolling(function() { var scrollTop = renderer.scrollTop;
renderer.scrollBy(0, rows * config.lineHeight);
if (select != null) renderer.scrollBy(0, rows * config.lineHeight);
renderer.scrollCursorIntoView(null, 0.5); if (select != null)
}, this); renderer.scrollCursorIntoView(null, 0.5);
renderer.animateScrolling(scrollTop);
}; };
this.selectPageDown = function() { this.selectPageDown = function() {
@ -1076,15 +1078,15 @@ var Editor = function(renderer, session) {
this.gotoLine = function(lineNumber, column, animate) { this.gotoLine = function(lineNumber, column, animate) {
this.selection.clearSelection(); this.selection.clearSelection();
this.session.unfold({row: lineNumber - 1, column: column || 0}); this.session.unfold({row: lineNumber - 1, column: column || 0});
this.$blockScrolling += 1; this.$blockScrolling += 1;
this.moveCursorTo(lineNumber - 1, column || 0); this.moveCursorTo(lineNumber - 1, column || 0);
this.$blockScrolling -= 1; this.$blockScrolling -= 1;
if (!this.isRowFullyVisible(lineNumber - 1)) if (!this.isRowFullyVisible(lineNumber - 1))
this.scrollToLine(lineNumber - 1, true, animate); this.scrollToLine(lineNumber - 1, true, animate);
}; };
this.navigateTo = function(row, column) { this.navigateTo = function(row, column) {
this.clearSelection(); this.clearSelection();
this.moveCursorTo(row, column); this.moveCursorTo(row, column);
@ -1141,17 +1143,17 @@ var Editor = function(renderer, session) {
}; };
this.navigateFileEnd = function() { this.navigateFileEnd = function() {
this.renderer.animateScrolling(function() { var scrollTop = this.renderer.scrollTop;
this.selection.moveCursorFileEnd(); this.selection.moveCursorFileEnd();
this.clearSelection(); this.clearSelection();
}, this); this.renderer.animateScrolling(scrollTop);
}; };
this.navigateFileStart = function() { this.navigateFileStart = function() {
this.renderer.animateScrolling(function() { var scrollTop = this.renderer.scrollTop;
this.selection.moveCursorFileStart(); this.selection.moveCursorFileStart();
this.clearSelection(); this.clearSelection();
}, this); this.renderer.animateScrolling(scrollTop);
}; };
this.navigateWordRight = function() { this.navigateWordRight = function() {
@ -1261,9 +1263,9 @@ var Editor = function(renderer, session) {
this.selection.setSelectionRange(range); this.selection.setSelectionRange(range);
this.$blockScrolling -= 1; this.$blockScrolling -= 1;
this.renderer.animateScrolling(function() { var scrollTop = this.renderer.scrollTop;
this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5); this.renderer.scrollSelectionIntoView(range.start, range.end, 0.5);
}, this); this.renderer.animateScrolling(scrollTop);
} }
}; };

View file

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