From 9dd93c52b077c59f719486fdaa7309884bb0c1b5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 10 Oct 2019 16:39:41 +0200 Subject: [PATCH] safeguard if the offsetnode is null when determining caret position --- src/editor/dom.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/editor/dom.js b/src/editor/dom.js index 9073eb37a3..e82c3f70ca 100644 --- a/src/editor/dom.js +++ b/src/editor/dom.js @@ -92,6 +92,10 @@ function getSelectionOffsetAndText(editor, selectionNode, selectionOffset) { // gets the caret position details, ignoring and adjusting to // the ZWS if you're typing in a caret node function getCaret(node, offsetToNode, offsetWithinNode) { + // if no node is selected, return an offset at the start + if (!node) { + return new DocumentOffset(0, false); + } let atNodeEnd = offsetWithinNode === node.textContent.length; if (node.nodeType === Node.TEXT_NODE && isCaretNode(node.parentElement)) { const zwsIdx = node.nodeValue.indexOf(CARET_NODE_CHAR);