LibWeb: Only clear command states and values if range actually changed

This commit is contained in:
Jelle Raaijmakers 2025-01-24 10:44:21 +01:00 committed by Andreas Kling
commit 486bce8dad
Notes: github-actions[bot] 2025-01-24 22:54:50 +00:00
2 changed files with 14 additions and 2 deletions

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2025, Jelle Raaijmakers <jelle@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -41,6 +42,14 @@ public:
return start_container() == end_container() && start_offset() == end_offset();
}
bool operator==(AbstractRange const& other) const
{
return start_container() == other.start_container()
&& start_offset() == other.start_offset()
&& end_container() == other.end_container()
&& end_offset() == other.end_offset();
}
protected:
AbstractRange(GC::Ref<Node> start_container, WebIDL::UnsignedLong start_offset, GC::Ref<Node> end_container, WebIDL::UnsignedLong end_offset);

View file

@ -467,6 +467,7 @@ void Selection::set_range(GC::Ptr<DOM::Range> range)
if (m_range)
m_range->set_associated_selection({}, nullptr);
auto range_changed = ((m_range == nullptr) != (range == nullptr)) || (m_range && *m_range != *range);
m_range = range;
if (m_range)
@ -476,9 +477,11 @@ void Selection::set_range(GC::Ptr<DOM::Range> range)
// Whenever the number of ranges in the selection changes to something different, and whenever a boundary point of
// the range at a given index in the selection changes to something different, the state override and value override
// must be unset for every command.
if (range_changed) {
m_document->reset_command_state_overrides();
m_document->reset_command_value_overrides();
}
}
GC::Ptr<DOM::Position> Selection::cursor_position() const
{