diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp index e442b284598b0..433884bc52e63 100644 --- a/Libraries/LibWeb/Editing/Commands.cpp +++ b/Libraries/LibWeb/Editing/Commands.cpp @@ -25,6 +25,20 @@ namespace Web::Editing { +// https://w3c.github.io/editing/docs/execCommand/#the-bold-command +bool command_bold_action(DOM::Document& document, String const&) +{ + // If queryCommandState("bold") returns true, set the selection's value to "normal". + if (document.query_command_state(CommandNames::bold)) + set_the_selections_value(document, CommandNames::bold, "normal"_string); + + // Otherwise set the selection's value to "bold". + set_the_selections_value(document, CommandNames::bold, "bold"_string); + + // Either way, return true. + return true; +} + // https://w3c.github.io/editing/docs/execCommand/#the-defaultparagraphseparator-command bool command_default_paragraph_separator_action(DOM::Document& document, String const& input_value) { @@ -834,6 +848,13 @@ bool command_style_with_css_state(DOM::Document const& document) } static Array const commands { + // https://w3c.github.io/editing/docs/execCommand/#the-bold-command + CommandDefinition { + .command = CommandNames::bold, + .action = command_bold_action, + .relevant_css_property = CSS::PropertyID::FontWeight, + .inline_activated_values = { "bold"_string, "600"_string, "700"_string, "800"_string, "900"_string }, + }, // https://w3c.github.io/editing/docs/execCommand/#the-delete-command CommandDefinition { .command = CommandNames::delete_, diff --git a/Libraries/LibWeb/Editing/Commands.h b/Libraries/LibWeb/Editing/Commands.h index 58fedab11761a..9b1634f6309f8 100644 --- a/Libraries/LibWeb/Editing/Commands.h +++ b/Libraries/LibWeb/Editing/Commands.h @@ -29,6 +29,7 @@ struct CommandDefinition { Optional find_command_definition(FlyString const&); // Command implementations +bool command_bold_action(DOM::Document&, String const&); bool command_default_paragraph_separator_action(DOM::Document&, String const&); String command_default_paragraph_separator_value(DOM::Document const&); bool command_delete_action(DOM::Document&, String const&);