Skip to content

Commit

Permalink
Save and restore window scroll position on paste
Browse files Browse the repository at this point in the history
Closes #222
  • Loading branch information
jhchen committed Oct 20, 2014
1 parent bb70b25 commit 63b3eb3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/modules/paste-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class PasteManager
return unless range?
@container.innerHTML = ""
iframe = dom(@quill.root).window()
scrollY = iframe.scrollY
iframeScrollY = iframe.scrollY
windowScrollX = window.scrollX
windowScrollY = window.scrollY
@container.focus()
_.defer( =>
doc = new Document(@container, @quill.options)
Expand All @@ -36,9 +38,10 @@ class PasteManager
@quill.setSelection(range.start + lengthAdded, range.start + lengthAdded)
[line, offset] = @quill.editor.doc.findLineAt(range.start + lengthAdded)
lineBottom = line.node.offsetTop + line.node.offsetHeight
if lineBottom > scrollY + @quill.root.offsetHeight
scrollY = line.node.offsetTop - @quill.root.offsetHeight / 2
iframe.scrollTo(0, scrollY)
if lineBottom > iframeScrollY + @quill.root.offsetHeight
iframeScrollY = line.node.offsetTop - @quill.root.offsetHeight / 2
iframe.scrollTo(0, iframeScrollY)
window.scrollTo(windowScrollX, windowScrollY)
)


Expand Down

0 comments on commit 63b3eb3

Please sign in to comment.