Bug 1947107 - Rename WhiteSpaceVisibilityKeeper::ReplaceText r=m_kato

Despite the name, it does not replace text of the specified the range.

The range is not collapsed only when updating composition string and even in
the case, `EditorBase::InsertTextWithTransaction` automatically creates
a `CompositionTransaction` and the transaction will delete the existing
composition string before inserting the new string.

For making the job of the method clearer, this patch renames it as
`InsertOrUpdateCompositionString` and it's actually implemented by
`InsertTextOrInsertOrUpdateCompositionString`.

Differential Revision: https://phabricator.services.mozilla.com/D237525
This commit is contained in:
Masayuki Nakano
2025-02-13 04:29:46 +00:00
parent 8f725d7683
commit 6b49882e22
3 changed files with 60 additions and 23 deletions

View File

@@ -1234,15 +1234,14 @@ Result<EditActionResult, nsresult> HTMLEditor::HandleInsertText(
return EditActionResult::HandledResult();
}
auto compositionEndPoint = GetLastIMESelectionEndPoint<EditorDOMPoint>();
if (!compositionEndPoint.IsSet()) {
compositionEndPoint = pointToInsert;
}
const auto compositionEndPoint =
GetLastIMESelectionEndPoint<EditorDOMPoint>();
Result<InsertTextResult, nsresult> replaceTextResult =
WhiteSpaceVisibilityKeeper::ReplaceText(
WhiteSpaceVisibilityKeeper::InsertOrUpdateCompositionString(
*this, aInsertionString,
EditorDOMRange(pointToInsert, compositionEndPoint),
InsertTextTo::ExistingTextNodeIfAvailable);
compositionEndPoint.IsSet()
? EditorDOMRange(pointToInsert, compositionEndPoint)
: EditorDOMRange(pointToInsert));
if (MOZ_UNLIKELY(replaceTextResult.isErr())) {
NS_WARNING("WhiteSpaceVisibilityKeeper::ReplaceText() failed");
return replaceTextResult.propagateErr();