mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
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.
32 lines
1.3 KiB
HTML
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>
|