Bug 1937696 - part 1: Make HTMLEditor::InsertPaddingBRElementIfNeeded insert a padding <br> rather than a normal <br> r=m_kato

Using normal `<br>` for padding `<br>` makes notifying IME of the mutation
because `ContentEventHandler` ignores only padding `<br>` elements.  Therefore,
we should make it use a padding `<br>` for hiding the mutations from IME since
IME may be confused at unexpected text change notifications.

Differential Revision: https://phabricator.services.mozilla.com/D232601
This commit is contained in:
Masayuki Nakano
2025-01-15 00:56:03 +00:00
parent dccfdca702
commit 6e2a06be92
2 changed files with 11 additions and 7 deletions

View File

@@ -11254,16 +11254,20 @@ HTMLEditor::InsertPaddingBRElementIfNeeded(
return Err(rv);
}
}
// TODO: Insert padding <br> for the last empty line if the point is
// immediately after a block boundary. However, we should not use the flag
// anymore because we should use linefeed in preformatted text.
// Padding <br> elements may appear and disappear a lot even during IME has a
// composition. Therefore, IME may be confused with the mutation if we use
// normal <br> element since it does not match with expectation of IME. For
// hiding the mutations from IME, we need to set the new <br> element flag to
// NS_PADDING_FOR_EMPTY_LAST_LINE.
Result<CreateElementResult, nsresult> insertPaddingBRResultOrError =
InsertBRElement(WithTransaction::Yes, BRElementType::Normal,
InsertBRElement(WithTransaction::Yes,
BRElementType::PaddingForEmptyLastLine,
pointToInsertPaddingBR);
if (MOZ_UNLIKELY(insertPaddingBRResultOrError.isErr())) {
NS_WARNING(
"EditorBase::InsertBRElement(WithTransaction::Yes, "
"BRElementType::Normal) failed");
"BRElementType::PaddingForEmptyLastLine) failed");
return insertPaddingBRResultOrError.propagateErr();
}
return CreateLineBreakResult(insertPaddingBRResultOrError.unwrap());