From 42993e708a6e95d38a1e76f3918a63f1580b2a33 Mon Sep 17 00:00:00 2001 From: Roelie Date: Tue, 19 May 2020 15:24:11 +0200 Subject: [PATCH] Get the selection from the prosemirror root insteadd of the window --- src/plugins/sync-plugin.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/plugins/sync-plugin.js b/src/plugins/sync-plugin.js index 9e9de31..3e51501 100644 --- a/src/plugins/sync-plugin.js +++ b/src/plugins/sync-plugin.js @@ -187,24 +187,6 @@ const getElementFromTextNode = node => { return node.parentElement } -const isDomSelectionInView = () => { - const selection = window.getSelection() - const anchorElement = getElementFromTextNode(selection.anchorNode) - if (selection && isInViewport(anchorElement)) { - const focusElement = getElementFromTextNode(selection.focusNode) - if (focusElement === anchorElement || - focusElement === selection.anchorNode || - selection.focusNode === focusElement || - selection.focusNode === selection.anchorNode || - isInViewport(focusElement) - ) { - return true - } - } - - return false -} - const isInViewport = element => { const bounding = element.getBoundingClientRect() const documentElement = dom.doc.documentElement @@ -261,11 +243,29 @@ export class ProsemirrorBinding { setTimeout(() => { this._domSelectionInView = null }, 0) - this._domSelectionInView = isDomSelectionInView() + this._domSelectionInView = this._isDomSelectionInView() } return this._domSelectionInView } + _isDomSelectionInView () { + const selection = this.prosemirrorView._root.getSelection() + const anchorElement = getElementFromTextNode(selection.anchorNode) + if (selection && isInViewport(anchorElement)) { + const focusElement = getElementFromTextNode(selection.focusNode) + if (focusElement === anchorElement || + focusElement === selection.anchorNode || + selection.focusNode === focusElement || + selection.focusNode === selection.anchorNode || + isInViewport(focusElement) + ) { + return true + } + } + + return false + } + renderSnapshot (snapshot, prevSnapshot) { if (!prevSnapshot) { prevSnapshot = Y.createSnapshot(Y.createDeleteSet(), new Map())