diff --git a/lib/ace/ext/error_marker.js b/lib/ace/ext/error_marker.js index a55e9a25..28663c6d 100644 --- a/lib/ace/ext/error_marker.js +++ b/lib/ace/ext/error_marker.js @@ -171,6 +171,8 @@ exports.showErrorMarker = function(editor, dir) { editor.session.widgetManager.addLineWidget(w); w.el.onmousedown = editor.focus.bind(editor); + + editor.renderer.scrollCursorIntoView(null, 0.5, {bottom: w.el.offsetHeight}); }; diff --git a/lib/ace/virtual_renderer.js b/lib/ace/virtual_renderer.js index 37acb23e..d00a8c19 100644 --- a/lib/ace/virtual_renderer.js +++ b/lib/ace/virtual_renderer.js @@ -1114,7 +1114,7 @@ var VirtualRenderer = function(container, theme) { * * Scrolls the cursor into the first visibile area of the editor **/ - this.scrollCursorIntoView = function(cursor, offset) { + this.scrollCursorIntoView = function(cursor, offset, $viewMargin) { // the editor is not visible if (this.$size.scrollerHeight === 0) return; @@ -1124,17 +1124,18 @@ var VirtualRenderer = function(container, theme) { var left = pos.left; var top = pos.top; + var topMargin = $viewMargin && $viewMargin.top || 0; + var bottomMargin = $viewMargin && $viewMargin.bottom || 0; + var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop; - - if (scrollTop > top) { + + if (scrollTop + topMargin > top) { if (offset) top -= offset * this.$size.scrollerHeight; - if (top == 0) - top = - this.scrollMargin.top; - else if (top == 0) - top = + this.scrollMargin.bottom; + if (top === 0) + top = -this.scrollMargin.top; this.session.setScrollTop(top); - } else if (scrollTop + this.$size.scrollerHeight < top + this.lineHeight) { + } else if (scrollTop + this.$size.scrollerHeight - bottomMargin < top + this.lineHeight) { if (offset) top += offset * this.$size.scrollerHeight; this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);