diff --git a/package.json b/package.json index d2d8a73..2e22b0b 100644 --- a/package.json +++ b/package.json @@ -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/*", diff --git a/src/plugins/sync-plugin.js b/src/plugins/sync-plugin.js index dffc30d..557fed0 100644 --- a/src/plugins/sync-plugin.js +++ b/src/plugins/sync-plugin.js @@ -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) @@ -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