Bug 1940377 - part 5: Make HTMLEditor::InsertElementAtSelectionAsAction normalize white-spaces around the insertion point if the new normalizer is enabled r=m_kato

Surprisingly, it has not normalize white-spaces around it. So, in some edge
cases, it might cause changing visibility of surrounding white-spaces.

Differential Revision: https://phabricator.services.mozilla.com/D239467
This commit is contained in:
Masayuki Nakano
2025-03-08 22:31:56 +00:00
parent a4270d20ef
commit 1dc6c56a97
2 changed files with 16 additions and 21 deletions

View File

@@ -2248,6 +2248,22 @@ nsresult HTMLEditor::InsertElementAtSelectionAsAction(
NS_WARNING("HTMLEditUtils::GetBetterInsertionPointFor() failed");
return NS_ERROR_FAILURE;
}
if (StaticPrefs::editor_white_space_normalization_blink_compatible()) {
Result<EditorDOMPoint, nsresult> pointToInsertOrError =
WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesToSplitAt(
*this, pointToInsert,
{WhiteSpaceVisibilityKeeper::NormalizeOption::
StopIfFollowingWhiteSpacesStartsWithNBSP});
if (MOZ_UNLIKELY(pointToInsertOrError.isErr())) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesToSplitAt() failed");
return pointToInsertOrError.propagateErr();
}
pointToInsert = pointToInsertOrError.unwrap();
if (NS_WARN_IF(!pointToInsert.IsSetAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
if (aOptions.contains(InsertElementOption::SplitAncestorInlineElements)) {
if (const RefPtr<Element> topmostInlineElement = Element::FromNodeOrNull(