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) ->
# 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