mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
LibWeb: Implement document.execCommand("defaultParagraphSeparator")
This commit is contained in:
parent
7bb865052a
commit
4a64557876
Notes:
github-actions[bot]
2024-11-30 16:37:16 +00:00
Author: https://github.com/gmta Commit: https://github.com/LadybirdBrowser/ladybird/commit/4a645578764 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2655 Reviewed-by: https://github.com/shannonbooth Reviewed-by: https://github.com/yyny
3 changed files with 38 additions and 0 deletions
|
@ -749,6 +749,10 @@ public:
|
|||
|
||||
GC::Ref<EditingHostManager> editing_host_manager() const { return *m_editing_host_manager; }
|
||||
|
||||
// // https://w3c.github.io/editing/docs/execCommand/#default-single-line-container-name
|
||||
FlyString const& default_single_line_container_name() const { return m_default_single_line_container_name; }
|
||||
void set_default_single_line_container_name(FlyString const& name) { m_default_single_line_container_name = name; }
|
||||
|
||||
protected:
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
@ -1039,6 +1043,9 @@ private:
|
|||
mutable OwnPtr<Unicode::Segmenter> m_word_segmenter;
|
||||
|
||||
GC::Ref<EditingHostManager> m_editing_host_manager;
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#default-single-line-container-name
|
||||
FlyString m_default_single_line_container_name { HTML::TagNames::div };
|
||||
};
|
||||
|
||||
template<>
|
||||
|
|
|
@ -19,6 +19,34 @@
|
|||
|
||||
namespace Web::Editing {
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-defaultparagraphseparator-command
|
||||
bool command_default_paragraph_separator_action(DOM::Document& document, String const& input_value)
|
||||
{
|
||||
// Let value be converted to ASCII lowercase.
|
||||
auto value = input_value.to_ascii_lowercase();
|
||||
|
||||
// If value is then equal to "p" or "div", set the context object's default single-line
|
||||
// container name to value, then return true.
|
||||
if (value == HTML::TagNames::p) {
|
||||
document.set_default_single_line_container_name(HTML::TagNames::p);
|
||||
return true;
|
||||
}
|
||||
if (value == HTML::TagNames::div) {
|
||||
document.set_default_single_line_container_name(HTML::TagNames::div);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-defaultparagraphseparator-command
|
||||
String command_default_paragraph_separator_value(DOM::Document const& document)
|
||||
{
|
||||
// Return the context object's default single-line container name.
|
||||
return document.default_single_line_container_name().to_string();
|
||||
}
|
||||
|
||||
// https://w3c.github.io/editing/docs/execCommand/#the-delete-command
|
||||
bool command_delete_action(DOM::Document& document, String const&)
|
||||
{
|
||||
|
@ -326,6 +354,7 @@ bool command_delete_action(DOM::Document& document, String const&)
|
|||
|
||||
static Array const commands {
|
||||
CommandDefinition { CommandNames::delete_, command_delete_action, {}, {}, {} },
|
||||
CommandDefinition { CommandNames::defaultParagraphSeparator, command_default_paragraph_separator_action, {}, {}, command_default_paragraph_separator_value },
|
||||
};
|
||||
|
||||
Optional<CommandDefinition const&> find_command_definition(FlyString const& command)
|
||||
|
|
|
@ -21,6 +21,8 @@ struct CommandDefinition {
|
|||
Optional<CommandDefinition const&> find_command_definition(FlyString const&);
|
||||
|
||||
// Command implementations
|
||||
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&);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue