Skip to content

Commit

Permalink
Make HTMLEditUtils treat <br> elements always inline
Browse files Browse the repository at this point in the history
As far as I've tested, `<br>` element is always treated as usual even if its
`display` is set to anything except `none`.  Therefore, preceding collapsible
white-spaces and `<br>` element should be treated as visible even if the
following `<br>` element is `display:block` or something.

Note that if `display:none` is specified, we should not treat it as a line
break, but our editor cannot work properly in the case and `HTMLEditUtils`
currently uses the default style of HTML elements if `display:none` is
specified.  Therefore, this patch makes `HTMLEditUtils` always treat `<br>`
as inline.

Differential Revision: https://phabricator.services.mozilla.com/D203403

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1881906
gecko-commit: b3c409d3ff5a2ad3721c3dd0177f86dc1129ebb1
gecko-reviewers: m_kato
  • Loading branch information
masayuki-nakano authored and moz-wptsync-bot committed Mar 6, 2024
1 parent 6633807 commit e4965ba
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions editing/other/inserttext-at-end-of-block-when-br-always-block.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Typing white-space and another character at end of a block should preserve the white-space when br element is always block</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
br { display: block; }
</style>
<script>
"use strict";

addEventListener("load", () => {
test(
() => {
const editingHost = document.querySelector("div[contenteditable]");
editingHost.focus();
getSelection().collapse(editingHost.firstChild, "abc".length);
document.execCommand("insertText", false, " ");
document.execCommand("insertText", false, "d");
assert_in_array(
editingHost.innerHTML,
[
"abc d",
"abc d<br>",
]
);
},
"Inserting white-space and a character at block end should keep the white-space even before block <br> element"
);
}, {once: true});
</script>
</head>
<body><div contenteditable>abc</div></body>
</html>

0 comments on commit e4965ba

Please sign in to comment.