diff --git a/lib/ace/editor.js b/lib/ace/editor.js index dd38d67d..96baea30 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -1205,8 +1205,7 @@ var Editor = function(renderer, session) { var range = this.$search.find(this.session); if (range) { this.session.unfold(range); - this.gotoLine(range.end.row+1, range.end.column); - this.selection.setSelectionRange(range); + this.selection.setSelectionRange(range); // this scrolls selection into view } }; diff --git a/lib/ace/layer/cursor.js b/lib/ace/layer/cursor.js index 811d5df0..5fa7644a 100644 --- a/lib/ace/layer/cursor.js +++ b/lib/ace/layer/cursor.js @@ -93,7 +93,7 @@ var Cursor = function(parentEl) { }, 1000); }; - this.getPixelPosition = function(onScreen) { + this.getPixelPosition = function(position, onScreen) { if (!this.config || !this.session) { return { left : 0, @@ -101,7 +101,8 @@ var Cursor = function(parentEl) { }; } - var position = this.session.selection.getCursor(); + if (!position) + position = this.session.selection.getCursor(); var pos = this.session.documentToScreenPosition(position); var cursorLeft = Math.round(this.$padding + pos.column * this.config.characterWidth); @@ -117,7 +118,7 @@ var Cursor = function(parentEl) { this.update = function(config) { this.config = config; - this.pixelPos = this.getPixelPosition(true); + this.pixelPos = this.getPixelPosition(null, true); this.cursor.style.left = this.pixelPos.left + "px"; this.cursor.style.top = this.pixelPos.top + "px"; diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 260525d0..b74945f1 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -685,15 +685,11 @@ var VirtualRenderer = function(container, theme) { }; this.scrollToLine = function(line, center) { - var lineHeight = { lineHeight: this.lineHeight }; - var offset = 0; - for (var l = 1; l < line; l++) { - offset += this.session.getRowHeight(lineHeight, l-1); - } - - if (center) { + var pos = this.$cursorLayer.getPixelPosition({row: line, column: 0}); + var offset = pos.top; + if (center) offset -= this.$size.scrollerHeight / 2; - } + this.session.setScrollTop(offset); };