mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-25 03:05:34 +00:00
23a22c597a
Editor creates a `<br>` element to end of a block if last line of the block is empty because caret should be placed as there is an empty line. Such special `<br>` element has `type` attribute whose value is "_moz". However, adding/removing the attribute is expensive and such hacky attribute shouldn't be referred nor changed by web apps. Therefore, this patch makes `HTMLBRElement` take another specific flag whether it's a special node for empty last line. For making the meaning clearer, this patch calls the such `<br>` elements as "padding `<br>` element for empty last line" insead of "moz-br". So, this patch also includes a lot of renaming methods and variables, and modifying related comments. Note that with this change, `IMEContentObserver` counts the padding `<br>` element in `<textarea>` because it's inserted before setting the new flag and setting the flag does not cause DOM tree mutation. This issue will be fixed by the following patches. Differential Revision: https://phabricator.services.mozilla.com/D39858 --HG-- extra : moz-landing-system : lando
52 lines
2.1 KiB
HTML
52 lines
2.1 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi=id=1385905
|
|
-->
|
|
<html>
|
|
<head>
|
|
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<script src="/tests/SimpleTest/EventUtils.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1385905">Mozilla Bug 1385905</a>
|
|
<div id="display"></div>
|
|
<div id="editor" contenteditable style="padding: 5px;"><div>contents</div></div>
|
|
<pre id="test">
|
|
</pre>
|
|
|
|
<script class="testbody" type="application/javascript">
|
|
SimpleTest.waitForExplicitFinish();
|
|
SimpleTest.waitForFocus(() => {
|
|
function ensureNoPaddingBR() {
|
|
for (let br of document.querySelectorAll("#editor > div > br")) {
|
|
ok(!SpecialPowers.wrap(br).isPaddingForEmptyLastLine,
|
|
"padding <br> element shouldn't be used with this test");
|
|
}
|
|
}
|
|
document.execCommand("defaultparagraphseparator", false, "div");
|
|
var editor = document.getElementById("editor");
|
|
// Click the left blank area of the first line to set cursor to the start of "contents".
|
|
synthesizeMouse(editor, 3, 10, {});
|
|
synthesizeKey("KEY_Enter");
|
|
is(editor.innerHTML, "<div><br></div><div>contents</div>",
|
|
"Typing Enter at start of the <div> element should split the <div> element");
|
|
synthesizeKey("KEY_ArrowUp");
|
|
sendString("x");
|
|
is(editor.innerHTML, "<div>x<br></div><div>contents</div>",
|
|
"Typing 'x' at the empty <div> element should just insert 'x' into the <div> element");
|
|
ensureNoPaddingBR();
|
|
synthesizeKey("KEY_Enter");
|
|
is(editor.innerHTML, "<div>x</div><div><br></div><div>contents</div>",
|
|
"Typing Enter next to 'x' in the first <div> element should split the <div> element and inserts <br> element to a new <div> element");
|
|
ensureNoPaddingBR();
|
|
synthesizeKey("KEY_Enter");
|
|
is(editor.innerHTML, "<div>x</div><div><br></div><div><br></div><div>contents</div>",
|
|
"Typing Enter in the empty <div> should split the <div> element and inserts <br> element to a new <div> element");
|
|
ensureNoPaddingBR();
|
|
SimpleTest.finish();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|