antonmedv/codejar

The `getSelection()` function throws an exception if `editor.parentNode` is a `ShadowRoot`.

angezid opened this issue · 2 comments

As it's turns out, this is a Firefox problem.

Well. We can fix it as well, maybe?

I ended up with JavaScript code:

function getSelection() {
  const root = editor.getRootNode();
  if(root.nodeType == Node.DOCUMENT_FRAGMENT_NODE) {
    try { return root.getSelection(); } catch(e) { } 
  }
  return window.getSelection();
}