From 2b7ff194f8f27608546bb4e14b59c19056df216c Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 24 Jan 2025 09:35:48 +0100 Subject: [PATCH] LibWeb: Only record overrides for editing commands that require it I forgot to implement the "If a command preserves overrides" part of the spec. --- Libraries/LibWeb/Editing/ExecCommand.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/Editing/ExecCommand.cpp b/Libraries/LibWeb/Editing/ExecCommand.cpp index b4405dbeae6..ae9c0f8ec47 100644 --- a/Libraries/LibWeb/Editing/ExecCommand.cpp +++ b/Libraries/LibWeb/Editing/ExecCommand.cpp @@ -75,18 +75,20 @@ WebIDL::ExceptionOr Document::exec_command(FlyString const& command, [[may // https://w3c.github.io/editing/docs/execCommand/#preserves-overrides // If a command preserves overrides, then before taking its action, the user agent must record current overrides. - auto overrides = Editing::record_current_overrides(*this); - - // 5. Take the action for command, passing value to the instructions as an argument. auto optional_command = Editing::find_command_definition(command); VERIFY(optional_command.has_value()); auto const& command_definition = optional_command.release_value(); + Vector overrides; + if (command_definition.preserves_overrides) + overrides = Editing::record_current_overrides(*this); + + // 5. Take the action for command, passing value to the instructions as an argument. auto command_result = command_definition.action(*this, value); // https://w3c.github.io/editing/docs/execCommand/#preserves-overrides // After taking the action, if the active range is collapsed, it must restore states and values from the recorded // list. - if (m_selection && m_selection->is_collapsed()) + if (!overrides.is_empty() && m_selection && m_selection->is_collapsed()) Editing::restore_states_and_values(*this, overrides); // 6. If the previous step returned false, return false.