diff --git a/editor/libeditor/HTMLEditUtils.cpp b/editor/libeditor/HTMLEditUtils.cpp index 047e0dd7e6e8..8c3d09c1e219 100644 --- a/editor/libeditor/HTMLEditUtils.cpp +++ b/editor/libeditor/HTMLEditUtils.cpp @@ -224,6 +224,12 @@ bool HTMLEditUtils::IsBlockElement(const nsIContent& aContent, if (MOZ_UNLIKELY(!aContent.IsElement())) { return false; } + // If it's a
, we should always treat it as an inline element because + // its preceding collapse white-spaces and another
works same as usual + // even if you set its style to `display:block`. + if (aContent.IsHTMLElement(nsGkAtoms::br)) { + return false; + } if (!StaticPrefs::editor_block_inline_check_use_computed_style() || aBlockInlineCheck == BlockInlineCheck::UseHTMLDefaultStyle) { return IsHTMLBlockElementByDefault(aContent); @@ -271,6 +277,12 @@ bool HTMLEditUtils::IsInlineContent(const nsIContent& aContent, if (!aContent.IsElement()) { return true; } + // If it's a
, we should always treat it as an inline element because + // its preceding collapse white-spaces and another
works same as usual + // even if you set its style to `display:block`. + if (aContent.IsHTMLElement(nsGkAtoms::br)) { + return true; + } if (!StaticPrefs::editor_block_inline_check_use_computed_style() || aBlockInlineCheck == BlockInlineCheck::UseHTMLDefaultStyle) { return !IsHTMLBlockElementByDefault(aContent); diff --git a/testing/web-platform/tests/editing/other/inserttext-at-end-of-block-when-br-always-block.html b/testing/web-platform/tests/editing/other/inserttext-at-end-of-block-when-br-always-block.html new file mode 100644 index 000000000000..922b8bd1c862 --- /dev/null +++ b/testing/web-platform/tests/editing/other/inserttext-at-end-of-block-when-br-always-block.html @@ -0,0 +1,36 @@ + + + + +Typing white-space and another character at end of a block should preserve the white-space when br element is always block + + + + + +
abc
+