fune/editor/libeditor/crashtests/1474978.html
Masayuki Nakano b56174de6b Bug 1792502 - Correct the emulation in crashtests for bug 1789967 r=m_kato
I misunderstood the traditional behavior before bug 1789967, that is,
`HTMLEditor` collapsed `Selection` to end of the deepest last child container
element **or text node** of the `<body>`, rather than to end of **only** the
deepest last child container element. This misunderstanding caused the backout
of the first landing, but I didn't realize this mistake.

Therefore, this patch makes the crashtests which are touched in bug 1789967 and
the collapsed point is at a text node (or failed to consider the collapsed
point) collapse `Selection` to end of the deepest last text node of their
`<body>` elements.

Differential Revision: https://phabricator.services.mozilla.com/D158177
2022-10-02 00:03:36 +00:00

21 lines
738 B
HTML

<script>
function onLoad() {
const dd = document.querySelector("dd[contenteditable]");
// For emulating the traditional behavior, collapse Selection to end of the
// text node at end of the <dd contenteditable> which is the deepest last
// child of the <body> (end of the text node after the <template>).
getSelection().collapse(dd.lastChild, dd.lastChild.length);
getSelection().setPosition(
document.querySelector("template")
);
dd.addEventListener("DOMNodeInserted", () => {
document.execCommand("selectAll");
document.execCommand("insertText", false, "");
});
document.execCommand("insertImage", false, "#");
}
</script>
<body onload="onLoad()">
<dd contenteditable>
<template></template>
</dd></body>