diff --git a/Libraries/LibWeb/DOM/AbstractRange.h b/Libraries/LibWeb/DOM/AbstractRange.h index cbcfdd6797b..fad72da2375 100644 --- a/Libraries/LibWeb/DOM/AbstractRange.h +++ b/Libraries/LibWeb/DOM/AbstractRange.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2022, Luke Wilde * Copyright (c) 2022, Andreas Kling + * Copyright (c) 2025, Jelle Raaijmakers * * 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 start_container, WebIDL::UnsignedLong start_offset, GC::Ref end_container, WebIDL::UnsignedLong end_offset); diff --git a/Libraries/LibWeb/Selection/Selection.cpp b/Libraries/LibWeb/Selection/Selection.cpp index 683449ba123..e548d89e8b7 100644 --- a/Libraries/LibWeb/Selection/Selection.cpp +++ b/Libraries/LibWeb/Selection/Selection.cpp @@ -467,6 +467,7 @@ void Selection::set_range(GC::Ptr 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,8 +477,10 @@ void Selection::set_range(GC::Ptr 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. - m_document->reset_command_state_overrides(); - m_document->reset_command_value_overrides(); + if (range_changed) { + m_document->reset_command_state_overrides(); + m_document->reset_command_value_overrides(); + } } GC::Ptr Selection::cursor_position() const