Skip to content

Commit

Permalink
LibWeb: Only record overrides for editing commands that require it
Browse files Browse the repository at this point in the history
I forgot to implement the "If a command preserves overrides" part of the
spec.
  • Loading branch information
gmta committed Jan 24, 2025
1 parent 5431045 commit 7d6760e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Libraries/LibWeb/Editing/ExecCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,20 @@ WebIDL::ExceptionOr<bool> 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<Editing::RecordedOverride> 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.
Expand Down

0 comments on commit 7d6760e

Please sign in to comment.