Skip to content

Commit

Permalink
LibWeb: Implement "bold" editing command
Browse files Browse the repository at this point in the history
  • Loading branch information
gmta committed Jan 7, 2025
1 parent 3740e1c commit 50974d5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Libraries/LibWeb/Editing/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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_,
Expand Down
1 change: 1 addition & 0 deletions Libraries/LibWeb/Editing/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct CommandDefinition {
Optional<CommandDefinition const&> 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&);
Expand Down

0 comments on commit 50974d5

Please sign in to comment.