From bf61fc34b74baf2fb7884fae344a31f0f9fc708d Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 2 Dec 2019 09:59:00 +0100 Subject: [PATCH] Polyfill ShadowRoot.getSelection when not available FIX: The `root` accessor on views now makes sure that, when it returns a shadow root, that object has a `getSelection` method. See https://discuss.prosemirror.net/t/prosemirror-inside-a-shadowroot/2387 --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 47858fc6..0757f8d0 100644 --- a/src/index.js +++ b/src/index.js @@ -247,8 +247,10 @@ export class EditorView { get root() { let cached = this._root if (cached == null) for (let search = this.dom.parentNode; search; search = search.parentNode) { - if (search.nodeType == 9 || (search.nodeType == 11 && search.host)) + if (search.nodeType == 9 || (search.nodeType == 11 && search.host)) { + if (!search.getSelection) Object.getPrototypeOf(search).getSelection = () => document.getSelection() return this._root = search + } } return cached || document }