Skip to content

Commit

Permalink
Fix scroll position bug - fixes #31 & closes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Dec 15, 2020
1 parent 7fdadaa commit 34a34d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"lint": "standard",
"watch": "rollup -wc",
"debug": "concurrently 'http-server -o test.html' 'npm run watch'",
"preversion": "npm run lint && npm run dist && npm run test"
"preversion": "npm run lint && npm run dist && npm run test",
"start": "concurrently 'http-server -o demo/prosemirror.html' 'npm run watch'"
},
"files": [
"dist/*",
Expand Down
13 changes: 12 additions & 1 deletion src/plugins/sync-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export class ProsemirrorBinding {
_isLocalCursorInView () {
if (!this.prosemirrorView.hasFocus()) return false
if (environment.isBrowser && this._domSelectionInView === null) {
// Calculte the domSelectionInView and clear by next tick after all events are finished
// Calculate the domSelectionInView and clear by next tick after all events are finished
setTimeout(() => {
this._domSelectionInView = null
}, 0)
Expand All @@ -234,6 +234,17 @@ export class ProsemirrorBinding {
range.setStart(selection.anchorNode, selection.anchorOffset)
range.setEnd(selection.focusNode, selection.focusOffset)

// This is a workaround for an edgecase where getBoundingClientRect will
// return zero values if the selection is collapsed at the start of a newline
// see reference here: https://stackoverflow.com/a/59780954
const rects = range.getClientRects()
if (rects.length === 0) {
// probably buggy newline behavior, explicitly select the node contents
if (range.startContainer && range.collapsed) {
range.selectNodeContents(range.startContainer)
}
}

const bounding = range.getBoundingClientRect()
const documentElement = dom.doc.documentElement

Expand Down

0 comments on commit 34a34d3

Please sign in to comment.