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.
This commit is contained in:
Aliaksandr Kalenik 2025-07-03 21:28:49 +02:00 committed by Jelle Raaijmakers
commit 5874b7a76f
Notes: github-actions[bot] 2025-07-03 20:17:46 +00:00
5 changed files with 73 additions and 12 deletions

View file

@ -39,7 +39,7 @@ public:
Gfx::Orientation orientation() const;
CSSPixelRect selection_rect() const;
CSSPixelRect range_rect(size_t start_offset_in_code_units, size_t end_offset_in_code_units) const;
CSSPixelRect range_rect(Paintable::SelectionState selection_state, size_t start_offset_in_code_units, size_t end_offset_in_code_units) const;
CSSPixels width() const { return m_size.width(); }
CSSPixels height() const { return m_size.height(); }