ladybird/Tests/LibWeb/Text/input/selection-in-focused-editing-host.html
Jelle Raaijmakers c9d4913bb4 LibWeb: Do not modify selection if editing host is already selected
If an editing host receives focus, we would always set a new selection
range. However, we only need to do that if we're not already part of the
active range. This corresponds to behavior shown by Chrome and Firefox.
2025-08-01 10:09:26 +02:00

26 lines
909 B
HTML

<!DOCTYPE html>
<div contenteditable>foo</div>
<script src="include.js"></script>
<script>
test(() => {
const divElm = document.querySelector('div[contenteditable]');
// Select the middle 'o'
let range = document.createRange();
range.setStart(divElm.childNodes[0], 1);
range.setEnd(divElm.childNodes[0], 2);
getSelection().addRange(range);
println(`Range: ${range.startContainer} ${range.startOffset} ${range.endContainer} ${range.endOffset}`);
println(`document.activeElement: ${document.activeElement}`);
// Refocus on the editing host
document.body.focus();
divElm.focus();
println('Selection must be the same as above:');
range = getSelection().getRangeAt(0);
println(`Range: ${range.startContainer} ${range.startOffset} ${range.endContainer} ${range.endOffset}`);
println(`document.activeElement: ${document.activeElement}`);
});
</script>