Skip to content

Commit

Permalink
fix(events): catch when posFromDOM returns -1 (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
whawker committed Oct 11, 2022
1 parent a64721a commit 8dc6628
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/sweet-radios-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@remirror/extension-events': patch
---

Catch when `posFromDom` returns -1, which causes a thrown error when attempting to resolve the pos
8 changes: 7 additions & 1 deletion packages/remirror__extension-events/src/events-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { EditorView } from '@remirror/core';
* inside the editor.
*/
function posAtDOM(view: EditorView, node: Node, offset: number, bias?: number): number | null {
return (view as any).docView.posFromDOM(node, offset, bias);
const pos = (view as any).docView.posFromDOM(node, offset, bias);

if (pos === null || pos < 0) {
return null;
}

return pos;
}

/**
Expand Down

1 comment on commit 8dc6628

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://remirror.io as production
🚀 Deployed on https://634523fa3dcbda0a5ebc8f42--remirror.netlify.app

Please sign in to comment.