Masayuki Nakano a353ab7e90 Bug 1789967 - part 3: Make HTMLEditor::CollapseSelectionToEndOfLastLeafNodeOfDocument and HTMLEditor::InitEditorContentAndSelection do nothing if the document is partially editable r=m_kato
They and their callees work with the result of `GetRoot()` which is the document
element or the body element.  If the body is not editable, `Selection` should
not be updated in non-editable region nor `<br>` elements should not be
inserted in both non-focused editable elements and non-editable elements.
Therefore, they should run only when the document element or the `<body>`
element is editable.

To keep testing crashtests as reported, this patch makes tests which have
`contenteditable` except `<html>` and `<body>` initialize `Selection` as
what we've done.  And clean up the tests for helping to port them to WPT
in the future (bug 1725850).

Differential Revision: https://phabricator.services.mozilla.com/D157408
2022-09-22 06:27:37 +00:00

19 lines
625 B
HTML

<script>
window.onload = () => {
// For emulating the traditional behavior, collapse Selection to end of the
// <body> (at the text node after the <input>).
getSelection().collapse(document.body, document.body.childNodes.length);
document.execCommand("insertHorizontalRule");
getSelection().collapse(
document.querySelector("b")
);
document.execCommand("forwardDelete");
}
function onFocusChangeOfInput() {
document.getSelection().setPosition(document.querySelector("pre"));
}
</script>
<pre>
<time contenteditable>a|</t>
<input onfocus="onFocusChangeOfInput()" autofocus onblur="onFocusChangeOfInput()">