mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-22 08:00:45 +00:00
This change fixes at least two issues: - `update_associated_selection()` is responsible for selectionchange dispatch, and we were incorrectly dispatching this event on ranges that were not associated with a selection. - `Range::get_client_rects()` was using `update_associated_selection()` to refresh the selection state in the paintable tree for the current range, but since a range might not be associated with a selection, this could make the painted selection reflect the state of an arbitrary range instead of the actual selection range. Fixes a bug on Discord where any text typed into the message input would get selected.
32 lines
1.1 KiB
HTML
32 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html class="reftest-wait">
|
|
<link
|
|
rel="match"
|
|
href="../expected/range-not-assiciated-with-selection-should-not-affect-it-ref.html"
|
|
/>
|
|
<body>
|
|
<p id="text">This is a simple sentence used to test range and selection rectangles.</p>
|
|
<script>
|
|
const textNode = document.getElementById("text").firstChild;
|
|
|
|
const sel = window.getSelection();
|
|
sel.removeAllRanges();
|
|
|
|
const selRange = document.createRange();
|
|
selRange.setStart(textNode, 5);
|
|
selRange.setEnd(textNode, 16);
|
|
sel.addRange(selRange);
|
|
|
|
requestAnimationFrame(() => {
|
|
const otherRange = document.createRange();
|
|
otherRange.setStart(textNode, 0);
|
|
otherRange.setEnd(textNode, 0);
|
|
|
|
// Requesting client rects on a range not associated with selection should not affect selection
|
|
otherRange.getClientRects();
|
|
|
|
document.documentElement.classList.remove("reftest-wait");
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|