Bug 1965607: Gracefully handle anonymous children in TextLeafPoint::ToDOMPoint. r=eeejay

Differential Revision: https://phabricator.services.mozilla.com/D248723
This commit is contained in:
James Teh
2025-05-13 00:07:09 +00:00
committed by jteh@mozilla.com
parent 886999efe0
commit 37f125f5e9

View File

@@ -586,9 +586,10 @@ std::pair<nsIContent*, uint32_t> TextLeafPoint::ToDOMPoint(
MOZ_ASSERT(mOffset == 0 || mOffset == 1);
nsIContent* parent = content->GetParent();
MOZ_ASSERT(parent);
auto childIndex = parent->ComputeIndexOf(content);
MOZ_ASSERT(childIndex);
return {parent, mOffset == 0 ? *childIndex : *childIndex + 1};
// ComputeIndexOf() could return Nothing if this is an anonymous child.
if (auto childIndex = parent->ComputeIndexOf(content)) {
return {parent, mOffset == 0 ? *childIndex : *childIndex + 1};
}
}
// This could be an empty editable container, whitespace or an empty doc. In