Reset scroll margins when changing document

This commit is contained in:
James Allen 2017-02-20 15:46:53 +01:00
parent 995fa6122b
commit b52e4a5d1c

View file

@ -187,20 +187,25 @@ define [
scope.$on "#{scope.name}:set-scroll-size", (e, size) -> scope.$on "#{scope.name}:set-scroll-size", (e, size) ->
# Make sure that the editor has enough scroll margin above and below # Make sure that the editor has enough scroll margin above and below
# to scroll the review panel with the given size # to scroll the review panel with the given size
marginChanged = false marginTop = size.overflowTop
if editor.renderer.scrollMargin.top != size.overflowTop
window.editors[0].renderer.scrollMargin.top = size.overflowTop
marginChanged = true
maxHeight = editor.renderer.layerConfig.maxHeight maxHeight = editor.renderer.layerConfig.maxHeight
marginBottom = Math.max(size.height - maxHeight, 0) 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 if editor.renderer.scrollMargin.bottom != marginBottom
editor.renderer.scrollMargin.bottom = marginBottom editor.renderer.scrollMargin.bottom = marginBottom
marginChanged = true marginChanged = true
if marginChanged if marginChanged
editor.renderer.updateFull() editor.renderer.updateFull()
resetScrollMargins = () ->
setScrollMargins(0,0)
scope.$watch "theme", (value) -> scope.$watch "theme", (value) ->
editor.setTheme("ace/theme/#{value}") editor.setTheme("ace/theme/#{value}")
@ -325,6 +330,8 @@ define [
sharejs_doc.attachToAce(editor) sharejs_doc.attachToAce(editor)
editor.initing = false editor.initing = false
resetScrollMargins()
# need to set annotations after attaching because attaching # need to set annotations after attaching because attaching
# deletes and then inserts document content # deletes and then inserts document content
session.setAnnotations scope.annotations session.setAnnotations scope.annotations