Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getBounds of empty text nodes #3491

Merged
merged 1 commit into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down