coding styles

This commit is contained in:
Fabian Jakobs 2012-04-11 17:19:56 +02:00
commit 2208ccdd48

View file

@ -725,25 +725,24 @@ var VirtualRenderer = function(container, theme) {
this.session.setScrollTop(row * this.lineHeight); this.session.setScrollTop(row * this.lineHeight);
}; };
//@todo I would like to make this animation a setting. How? this.STEPS = 10;
this.$calcSteps = function(fromValue, toValue){
var i = 0;
var l = STEPS;
var steps = [];
var STEPS = 10; var func = function(t, x_min, dx) {
function calcSteps(fromValue, toValue){ if ((t /= .5) < 1)
var i = 0, return dx / 2 * Math.pow(t, 3) + x_min;
l = STEPS, return dx / 2 * (Math.pow(t - 2, 3) + 2) + x_min;
steps = [], };
func = function(t, x_min, dx) {
if ((t /= .5) < 1)
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)
steps.push(func(i / STEPS, fromValue, toValue - fromValue)); steps.push(func(i / this.STEPS, fromValue, toValue - fromValue));
steps.push(toValue); steps.push(toValue);
return steps; return steps;
} };
this.scrollToLine = function(line, center) { this.scrollToLine = function(line, center) {
var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0});
@ -752,10 +751,12 @@ var VirtualRenderer = function(container, theme) {
offset -= this.$size.scrollerHeight / 2; offset -= this.$size.scrollerHeight / 2;
if (this.$animatedScroll && Math.abs(offset - this.scrollTop) < 10000) { if (this.$animatedScroll && Math.abs(offset - this.scrollTop) < 10000) {
var i = 0, _self = this, var i = 0;
steps = calcSteps(this.scrollTop, offset); var _self = this;
var steps = _self.$calcSteps(this.scrollTop, offset);
clearInterval(_self.$timer); clearInterval(_self.$timer);
this.$timer = setInterval(function(){ this.$timer = setInterval(function() {
_self.session.setScrollTop(steps[i]); _self.session.setScrollTop(steps[i]);
if (++i == STEPS + 1) if (++i == STEPS + 1)