diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 05f07e20..6945c533 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -964,22 +964,20 @@ var Editor = function(renderer, session) { var config = this.renderer.layerConfig; var rows = dir * Math.floor(config.height / config.lineHeight); - renderer.scrollBy(0, rows * config.lineHeight); - - if (select == null) - return; - this.$blockScrolling++; - if (select) { + if (select == true) { this.selection.$moveSelection(function(){ this.moveCursorBy(rows, 0); }); - } else { + } else if (select == false) { this.selection.moveCursorBy(rows, 0); this.selection.clearSelection(); } - this.$blockScrolling--; + + this.renderer.animateScrolling(function() { + renderer.scrollBy(0, rows * config.lineHeight); + }, this); }; this.selectPageDown = function() { @@ -1081,18 +1079,6 @@ var Editor = function(renderer, session) { 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(); this.moveCursorTo(row, column); @@ -1147,20 +1133,19 @@ var Editor = function(renderer, session) { this.selection.moveCursorLineEnd(); this.clearSelection(); }; - + this.navigateFileEnd = function() { - //this.selection.moveCursorFileEnd(); - var doc = this.session.getDocument(); - var row = doc.getLength() - 1; - - this.$gotoLine(row, doc.getLine(row).length); - this.clearSelection(); + this.renderer.animateScrolling(function() { + this.selection.moveCursorFileEnd(); + this.clearSelection(); + }, this); }; this.navigateFileStart = function() { - //this.selection.moveCursorFileStart(); - this.$gotoLine(0, 0); - this.clearSelection(); + this.renderer.animateScrolling(function() { + this.selection.moveCursorFileStart(); + this.clearSelection(); + }, this); }; this.navigateWordRight = function() { @@ -1265,24 +1250,14 @@ var Editor = function(renderer, session) { var range = this.$search.find(this.session); if (range) { - this.session.unfold(range); - this.$blockScrolling += 1; + this.session.unfold(range); this.selection.setSelectionRange(range); this.$blockScrolling -= 1; - if (this.getAnimatedScroll()) { - var cursor = this.getCursorPosition(); - if (!this.isRowFullyVisible(cursor.row)) - this.scrollToLine(cursor.row, true, animate); - - //@todo scroll X - //if (!this.isColumnFullyVisible(cursor.column)) - //this.scrollToRow(cursor.column); - } - else { + this.renderer.animateScrolling(function() { this.renderer.scrollSelectionIntoView(range.start, range.end); - } + }, this); } }; diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index d51c1cb1..4951ff66 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -108,7 +108,8 @@ var VirtualRenderer = function(container, theme) { this.scrollBar = new ScrollBar(container); this.scrollBar.addEventListener("scroll", function(e) { - _self.session.setScrollTop(e.data); + if (!_self.$inScrollAnimation) + _self.session.setScrollTop(e.data); }); this.scrollTop = 0; @@ -746,37 +747,53 @@ var VirtualRenderer = function(container, theme) { for (i = 0; i < l; ++i) steps.push(func(i / this.STEPS, fromValue, toValue - fromValue)); - steps.push(toValue); return steps; }; - this.scrollToLine = function(line, center, animate, callback) { + this.scrollToLine = function(line, center, animate) { var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); var offset = pos.top; if (center) offset -= this.$size.scrollerHeight / 2; - if (animate !== false - && this.$animatedScroll && Math.abs(offset - this.scrollTop) < 100000) { - var _self = this; - var steps = _self.$calcSteps(this.scrollTop, offset); - - clearInterval(this.$timer); - this.$timer = setInterval(function() { - _self.session.setScrollTop(steps.shift()); - - if (!steps.length) { - callback && callback(); - clearInterval(_self.$timer); - } - }, 10); - } - else { + if (animate) { + this.animateScrolling(function() { + this.session.setScrollTop(offset); + }, this); + } else { this.session.setScrollTop(offset); } }; + this.animateScrolling = function(scrollFunc, self) { + var fromValue = this.scrollTop; + scrollFunc.call(self); + var toValue = this.scrollTop; + if (this.$animatedScroll && Math.abs(fromValue - toValue) < 100000) { + var _self = this; + var steps = _self.$calcSteps(fromValue, toValue); + this.$inScrollAnimation = true; + + clearInterval(this.$timer); + + _self.session.setScrollTop(steps.shift()); + this.$timer = setInterval(function() { + if (steps.length) { + _self.session.setScrollTop(steps.shift()); + // trick session to think it's already scrolled to not loose toValue + _self.session.$scrollTop = toValue; + } else { + this.$inScrollAnimation = false; + clearInterval(_self.$timer); + + _self.session.$scrollTop = -1; + _self.session.setScrollTop(toValue); + } + }, 10); + } + }; + this.scrollToY = function(scrollTop) { // after calling scrollBar.setScrollTop // scrollbar sends us event with same scrollTop. ignore it