ladybird/Tests/LibWeb/Ref/input/range-not-assiciated-with-selection-should-not-affect-it.html
Aliaksandr Kalenik 5874b7a76f LibWeb: Skip update_associated_selection() when there's no selection
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.
2025-07-03 22:16:39 +02:00

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>