From ac70ecc00540af8ab80a969dd8f2e287bb0989ee Mon Sep 17 00:00:00 2001 From: Ruben Daniels Date: Sun, 22 Apr 2012 15:16:52 -0700 Subject: [PATCH] * Tweaked scroll animations * Added animations to pgup/pgdn goto start/end of document --- lib/ace/editor.js | 72 ++++++++++++++++++++++++------------- lib/ace/virtual_renderer.js | 15 ++++---- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 2af7837d..a73bcfc3 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -676,7 +676,7 @@ var Editor = function(renderer, session) { this.remove = function(dir) { if (this.selection.isEmpty()){ - if(dir == "left") + if (dir == "left") this.selection.selectLeft(); else this.selection.selectRight(); @@ -974,32 +974,32 @@ var Editor = function(renderer, session) { var row = this.$getPageDownRow(); var column = this.getCursorPositionScreen().column; - this.scrollToRow(row); - this.getSelection().moveCursorToScreen(row, column); + this.$gotoLine(row, column); + this.clearSelection(); }; this.gotoPageUp = function() { var row = this.$getPageUpRow(); var column = this.getCursorPositionScreen().column; - this.scrollToRow(row); - this.getSelection().moveCursorToScreen(row, column); + this.$gotoLine(row, column); + this.clearSelection(); }; this.scrollPageDown = function() { - this.scrollToRow(this.$getPageDownRow()); + this.scrollToLine(this.$getPageDownRow()); }; this.scrollPageUp = function() { - this.renderer.scrollToRow(this.$getPageUpRow()); + this.scrollToLine(this.$getPageUpRow()); }; this.scrollToRow = function(row) { this.renderer.scrollToRow(row); }; - this.scrollToLine = function(line, center) { - this.renderer.scrollToLine(line, center); + this.scrollToLine = function(line, center, animate, callback) { + this.renderer.scrollToLine(line, center, animate, callback); }; 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.session.unfold({row: lineNumber - 1, column: column || 0}); - + this.$blockScrolling += 1; - this.moveCursorTo(lineNumber-1, column || 0); + this.moveCursorTo(lineNumber - 1, column || 0); 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.clearSelection(); @@ -1122,14 +1135,25 @@ var Editor = function(renderer, session) { this.selection.moveCursorLineEnd(); this.clearSelection(); }; + + this.navigateLineEnd = function() { + //this.selection.moveCursorLineEnd(); + + this.clearSelection(); + }; 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.navigateFileStart = function() { - this.selection.moveCursorFileStart(); + //this.selection.moveCursorFileStart(); + this.$gotoLine(0, 0); this.clearSelection(); }; @@ -1206,31 +1230,31 @@ var Editor = function(renderer, session) { return this.$search.getOptions(); }; - this.find = function(needle, options) { + this.find = function(needle, options, animate) { this.clearSelection(); options = options || {}; options.needle = needle; this.$search.set(options); - this.$find(); + this.$find(false, animate); }; - this.findNext = function(options) { + this.findNext = function(options, animate) { options = options || {}; if (typeof options.backwards == "undefined") options.backwards = false; this.$search.set(options); - this.$find(); + this.$find(false, animate); }; - this.findPrevious = function(options) { + this.findPrevious = function(options, animate) { options = options || {}; if (typeof options.backwards == "undefined") options.backwards = true; this.$search.set(options); - this.$find(); + this.$find(false, animate); }; - this.$find = function(backwards) { + this.$find = function(backwards, animate) { if (!this.selection.isEmpty()) this.$search.set({needle: this.session.getTextRange(this.getSelectionRange())}); @@ -1248,7 +1272,7 @@ var Editor = function(renderer, session) { if (this.getAnimatedScroll()) { var cursor = this.getCursorPosition(); if (!this.isRowFullyVisible(cursor.row)) - this.scrollToLine(cursor.row, true); + this.scrollToLine(cursor.row, true, animate); //@todo scroll X //if (!this.isColumnFullyVisible(cursor.column)) diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 5fe79381..e67deb09 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -733,16 +733,14 @@ var VirtualRenderer = function(container, theme) { this.session.setScrollTop(row * this.lineHeight); }; - this.STEPS = 10; + this.STEPS = 7; this.$calcSteps = function(fromValue, toValue){ var i = 0; var l = this.STEPS; var steps = []; var 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; + return dx * (Math.pow(t - 1, 3) + 1) + x_min; }; for (i = 0; i < l; ++i) @@ -752,13 +750,14 @@ var VirtualRenderer = function(container, theme) { return steps; }; - this.scrollToLine = function(line, center) { + this.scrollToLine = function(line, center, animate, callback) { var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); var offset = pos.top; if (center) 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 steps = _self.$calcSteps(this.scrollTop, offset); @@ -766,8 +765,10 @@ var VirtualRenderer = function(container, theme) { this.$timer = setInterval(function() { _self.session.setScrollTop(steps.shift()); - if (!steps.length) + if (!steps.length) { + callback && callback(); clearInterval(_self.$timer); + } }, 10); } else {