* Tweaked scroll animations

* Added animations to pgup/pgdn goto start/end of document
This commit is contained in:
Ruben Daniels 2012-04-22 15:16:52 -07:00
commit ac70ecc005
2 changed files with 56 additions and 31 deletions

View file

@ -676,7 +676,7 @@ var Editor = function(renderer, session) {
this.remove = function(dir) { this.remove = function(dir) {
if (this.selection.isEmpty()){ if (this.selection.isEmpty()){
if(dir == "left") if (dir == "left")
this.selection.selectLeft(); this.selection.selectLeft();
else else
this.selection.selectRight(); this.selection.selectRight();
@ -974,32 +974,32 @@ var Editor = function(renderer, session) {
var row = this.$getPageDownRow(); var row = this.$getPageDownRow();
var column = this.getCursorPositionScreen().column; var column = this.getCursorPositionScreen().column;
this.scrollToRow(row); this.$gotoLine(row, column);
this.getSelection().moveCursorToScreen(row, column); this.clearSelection();
}; };
this.gotoPageUp = function() { this.gotoPageUp = function() {
var row = this.$getPageUpRow(); var row = this.$getPageUpRow();
var column = this.getCursorPositionScreen().column; var column = this.getCursorPositionScreen().column;
this.scrollToRow(row); this.$gotoLine(row, column);
this.getSelection().moveCursorToScreen(row, column); this.clearSelection();
}; };
this.scrollPageDown = function() { this.scrollPageDown = function() {
this.scrollToRow(this.$getPageDownRow()); this.scrollToLine(this.$getPageDownRow());
}; };
this.scrollPageUp = function() { this.scrollPageUp = function() {
this.renderer.scrollToRow(this.$getPageUpRow()); this.scrollToLine(this.$getPageUpRow());
}; };
this.scrollToRow = function(row) { this.scrollToRow = function(row) {
this.renderer.scrollToRow(row); this.renderer.scrollToRow(row);
}; };
this.scrollToLine = function(line, center) { this.scrollToLine = function(line, center, animate, callback) {
this.renderer.scrollToLine(line, center); this.renderer.scrollToLine(line, center, animate, callback);
}; };
this.centerSelection = function() { this.centerSelection = function() {
@ -1057,16 +1057,29 @@ var Editor = function(renderer, session) {
} }
}; };
this.gotoLine = function(lineNumber, column) { 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(this.getCursorPosition().row))
this.scrollToLine(lineNumber, true); if (!this.isRowFullyVisible(lineNumber - 1))
this.scrollToLine(lineNumber - 1, true, animate);
}; };
this.$gotoLine = function(row, column, animate, center) {
var _self = this;
//@todo hide cursor
this.scrollToLine(row, center, animate, function(){
_self.$blockScrolling += 1;
_self.moveCursorTo(row, column || 0);
_self.$blockScrolling -= 1;
});
}
this.navigateTo = function(row, column) { this.navigateTo = function(row, column) {
this.clearSelection(); this.clearSelection();
@ -1122,14 +1135,25 @@ var Editor = function(renderer, session) {
this.selection.moveCursorLineEnd(); this.selection.moveCursorLineEnd();
this.clearSelection(); this.clearSelection();
}; };
this.navigateLineEnd = function() {
//this.selection.moveCursorLineEnd();
this.clearSelection();
};
this.navigateFileEnd = function() { this.navigateFileEnd = function() {
this.selection.moveCursorFileEnd(); //this.selection.moveCursorFileEnd();
var doc = this.session.getDocument();
var row = doc.getLength() - 1;
this.$gotoLine(row, doc.getLine(row).length);
this.clearSelection(); this.clearSelection();
}; };
this.navigateFileStart = function() { this.navigateFileStart = function() {
this.selection.moveCursorFileStart(); //this.selection.moveCursorFileStart();
this.$gotoLine(0, 0);
this.clearSelection(); this.clearSelection();
}; };
@ -1206,31 +1230,31 @@ var Editor = function(renderer, session) {
return this.$search.getOptions(); return this.$search.getOptions();
}; };
this.find = function(needle, options) { this.find = function(needle, options, animate) {
this.clearSelection(); this.clearSelection();
options = options || {}; options = options || {};
options.needle = needle; options.needle = needle;
this.$search.set(options); this.$search.set(options);
this.$find(); this.$find(false, animate);
}; };
this.findNext = function(options) { this.findNext = function(options, animate) {
options = options || {}; options = options || {};
if (typeof options.backwards == "undefined") if (typeof options.backwards == "undefined")
options.backwards = false; options.backwards = false;
this.$search.set(options); this.$search.set(options);
this.$find(); this.$find(false, animate);
}; };
this.findPrevious = function(options) { this.findPrevious = function(options, animate) {
options = options || {}; options = options || {};
if (typeof options.backwards == "undefined") if (typeof options.backwards == "undefined")
options.backwards = true; options.backwards = true;
this.$search.set(options); this.$search.set(options);
this.$find(); this.$find(false, animate);
}; };
this.$find = function(backwards) { this.$find = function(backwards, animate) {
if (!this.selection.isEmpty()) if (!this.selection.isEmpty())
this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())}); this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())});
@ -1248,7 +1272,7 @@ var Editor = function(renderer, session) {
if (this.getAnimatedScroll()) { if (this.getAnimatedScroll()) {
var cursor = this.getCursorPosition(); var cursor = this.getCursorPosition();
if (!this.isRowFullyVisible(cursor.row)) if (!this.isRowFullyVisible(cursor.row))
this.scrollToLine(cursor.row, true); this.scrollToLine(cursor.row, true, animate);
//@todo scroll X //@todo scroll X
//if (!this.isColumnFullyVisible(cursor.column)) //if (!this.isColumnFullyVisible(cursor.column))

View file

@ -733,16 +733,14 @@ var VirtualRenderer = function(container, theme) {
this.session.setScrollTop(row * this.lineHeight); this.session.setScrollTop(row * this.lineHeight);
}; };
this.STEPS = 10; this.STEPS = 7;
this.$calcSteps = function(fromValue, toValue){ this.$calcSteps = function(fromValue, toValue){
var i = 0; var i = 0;
var l = this.STEPS; var l = this.STEPS;
var steps = []; var steps = [];
var func = function(t, x_min, dx) { var func = function(t, x_min, dx) {
if ((t /= .5) < 1) return dx * (Math.pow(t - 1, 3) + 1) + x_min;
return dx / 2 * Math.pow(t, 3) + x_min;
return dx / 2 * (Math.pow(t - 2, 3) + 2) + x_min;
}; };
for (i = 0; i < l; ++i) for (i = 0; i < l; ++i)
@ -752,13 +750,14 @@ var VirtualRenderer = function(container, theme) {
return steps; return steps;
}; };
this.scrollToLine = function(line, center) { 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 (this.$animatedScroll && Math.abs(offset - this.scrollTop) < 100000) { if (animate !== false
&& this.$animatedScroll && Math.abs(offset - this.scrollTop) < 100000) {
var _self = this; var _self = this;
var steps = _self.$calcSteps(this.scrollTop, offset); var steps = _self.$calcSteps(this.scrollTop, offset);
@ -766,8 +765,10 @@ var VirtualRenderer = function(container, theme) {
this.$timer = setInterval(function() { this.$timer = setInterval(function() {
_self.session.setScrollTop(steps.shift()); _self.session.setScrollTop(steps.shift());
if (!steps.length) if (!steps.length) {
callback && callback();
clearInterval(_self.$timer); clearInterval(_self.$timer);
}
}, 10); }, 10);
} }
else { else {