From b52e4a5d1c40081744744703a47eedb4c33f06ff Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 20 Feb 2017 15:46:53 +0100 Subject: [PATCH] Reset scroll margins when changing document --- .../ide/editor/directives/aceEditor.coffee | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee index b3c607455b..faa1159e00 100644 --- a/services/web/public/coffee/ide/editor/directives/aceEditor.coffee +++ b/services/web/public/coffee/ide/editor/directives/aceEditor.coffee @@ -187,20 +187,25 @@ define [ scope.$on "#{scope.name}:set-scroll-size", (e, size) -> # Make sure that the editor has enough scroll margin above and below # to scroll the review panel with the given size - marginChanged = false - if editor.renderer.scrollMargin.top != size.overflowTop - window.editors[0].renderer.scrollMargin.top = size.overflowTop - marginChanged = true - + marginTop = size.overflowTop maxHeight = editor.renderer.layerConfig.maxHeight marginBottom = Math.max(size.height - maxHeight, 0) + setScrollMargins(marginTop, marginBottom) + + setScrollMargins = (marginTop, marginBottom) -> + marginChanged = false + if editor.renderer.scrollMargin.top != marginTop + editor.renderer.scrollMargin.top = marginTop + marginChanged = true if editor.renderer.scrollMargin.bottom != marginBottom editor.renderer.scrollMargin.bottom = marginBottom marginChanged = true - if marginChanged editor.renderer.updateFull() + resetScrollMargins = () -> + setScrollMargins(0,0) + scope.$watch "theme", (value) -> editor.setTheme("ace/theme/#{value}") @@ -325,6 +330,8 @@ define [ sharejs_doc.attachToAce(editor) editor.initing = false + resetScrollMargins() + # need to set annotations after attaching because attaching # deletes and then inserts document content session.setAnnotations scope.annotations