Bug 1940377 - part 7: Make HTMLEditor normalize surrounding white-spaces of commit string r=m_kato

For avoiding invisible white-space issues around composition string and for
avoiding making `CompositionTransaction` confused, we normalize white-spaces
around composition string boundaries with using NBSPs more than usual.
Therefore, we need to recover them as usual when ending the composition.

Differential Revision: https://phabricator.services.mozilla.com/D239469
This commit is contained in:
Masayuki Nakano
2025-03-08 00:23:17 +00:00
parent f8da424b74
commit e04dcc4edc
3 changed files with 229 additions and 7 deletions

View File

@@ -1194,7 +1194,7 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleInsertText(
NS_WARNING("HTMLEditor::InsertTextWithTransaction() failed");
return insertEmptyTextResultOrError.propagateErr();
}
const InsertTextResult insertEmptyTextResult =
InsertTextResult insertEmptyTextResult =
insertEmptyTextResultOrError.unwrap();
nsresult rv = EnsureNoFollowingUnnecessaryLineBreak(
insertEmptyTextResult.EndOfInsertedTextRef());
@@ -1203,6 +1203,26 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleInsertText(
"HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak() failed");
return Err(rv);
}
const EditorDOMPoint& endOfInsertedText =
insertEmptyTextResult.EndOfInsertedTextRef();
if (StaticPrefs::editor_white_space_normalization_blink_compatible() &&
endOfInsertedText.IsInTextNode() &&
!endOfInsertedText.IsStartOfContainer()) {
nsresult rv = WhiteSpaceVisibilityKeeper::
NormalizeVisibleWhiteSpacesWithoutDeletingInvisibleWhiteSpaces(
*this, endOfInsertedText.AsInText().PreviousPoint());
if (NS_FAILED(rv)) {
NS_WARNING(
"WhiteSpaceVisibilityKeeper::"
"NormalizeVisibleWhiteSpacesWithoutDeletingInvisibleWhiteSpaces()"
" failed");
return Err(rv);
}
if (NS_WARN_IF(
!endOfInsertedText.IsInContentNodeAndValidInComposedDoc())) {
return Err(NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE);
}
}
// If we replaced non-empty composition string with an empty string,
// its preceding character may be a collapsible ASCII white-space.
// Therefore, we may need to insert a padding <br> after the white-space.