Skip to content

Commit

Permalink
Polyfill ShadowRoot.getSelection when not available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marijnh committed Dec 2, 2019
1 parent d44c736 commit bf61fc3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit bf61fc3

Please sign in to comment.