Files
ladybird/Tests/LibWeb/Text/input/selection-focuses-editing-host.html
Jelle Raaijmakers 738eb68dda LibWeb: Always focus on editing host if currently not focused
We were constraining the focusing behavior for editing hosts a bit too
much; regardless of how the selection changed, if the start container is
inside an editing host and it's currently not focused, we should focus
it. This fixes focus stealing by other elements that set a selection
inside an editing host on a click event, for example.
2025-08-20 11:36:40 +02:00

32 lines
1.3 KiB
HTML

<!DOCTYPE html>
<div id="a" contenteditable>foo</div>
<div id="b" contenteditable>foo<span>bar</span></div>
<button id="c">press me</button>
<script src="include.js"></script>
<script>
test(() => {
function reportSelectionAndFocus() {
const range = getSelection().getRangeAt(0);
println(`Range: ${range.startContainer} ${range.startOffset} ${range.endContainer} ${range.endOffset}`);
printElement(document.activeElement);
}
println('-- Simple editing host --');
const divA = document.querySelector('div#a');
getSelection().setBaseAndExtent(divA.childNodes[0], 1, divA.childNodes[0], 2);
reportSelectionAndFocus();
println('-- Editing host with nested <span> --');
const divB = document.querySelector('div#b');
getSelection().setBaseAndExtent(divB.childNodes[1].childNodes[0], 1, divB.childNodes[1].childNodes[0], 1);
reportSelectionAndFocus();
println('-- Refocusing on same editing host --');
const buttonElm = document.querySelector('button#c');
buttonElm.addEventListener('click', () => getSelection().setBaseAndExtent(divB.childNodes[0], 0, divB.childNodes[0], 0));
const buttonRect = buttonElm.getBoundingClientRect();
internals.click(buttonRect.left + 5, buttonRect.top + 5);
reportSelectionAndFocus();
});
</script>