From baecf477914f67f27b0f5d68a16f2ae6280989f4 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Mon, 29 Nov 2021 11:09:01 +0800 Subject: [PATCH] Fix getBounds of empty text nodes --- core/selection.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/selection.js b/core/selection.js index 8c3624dbe9..b099fad6e4 100644 --- a/core/selection.js +++ b/core/selection.js @@ -152,6 +152,14 @@ class Selection { let side = 'left'; let rect; if (node instanceof Text) { + // Return null if the text node is empty because it is + // not able to get a useful client rect: + // https://github.com/w3c/csswg-drafts/issues/2514. + // Empty text nodes are most likely caused by TextBlot#optimize() + // not getting called when editor content changes. + if (!node.data.length) { + return null; + } if (offset < node.data.length) { range.setStart(node, offset); range.setEnd(node, offset + 1);