mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 01:08:56 +00:00
LibWeb: Simplify delete and return actions in EditingHostManager
No functional changes.
This commit is contained in:
parent
60a501d824
commit
6c0a0b86ba
Notes:
github-actions[bot]
2025-08-26 08:27:32 +00:00
Author: https://github.com/gmta
Commit: 6c0a0b86ba
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5952
1 changed files with 8 additions and 18 deletions
|
@ -180,21 +180,16 @@ void EditingHostManager::handle_delete(DeleteDirection direction)
|
||||||
// When the user instructs the user agent to delete the next character inside an editing host, such as by pressing
|
// When the user instructs the user agent to delete the next character inside an editing host, such as by pressing
|
||||||
// the Delete key while the cursor is in an editable node, the user agent must call execCommand("forwarddelete") on
|
// the Delete key while the cursor is in an editable node, the user agent must call execCommand("forwarddelete") on
|
||||||
// the relevant document.
|
// the relevant document.
|
||||||
|
auto command = direction == DeleteDirection::Backward ? Editing::CommandNames::delete_ : Editing::CommandNames::forwardDelete;
|
||||||
auto editing_result = [&] {
|
auto editing_result = m_document->exec_command(command, false, {});
|
||||||
if (direction == DeleteDirection::Backward)
|
|
||||||
return m_document->exec_command(Editing::CommandNames::delete_, false, {});
|
|
||||||
if (direction == DeleteDirection::Forward)
|
|
||||||
return m_document->exec_command(Editing::CommandNames::forwardDelete, false, {});
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (editing_result.is_exception())
|
if (editing_result.is_exception())
|
||||||
dbgln("handle_delete(): editing resulted in exception: {}", editing_result.exception());
|
dbgln("handle_delete(): editing resulted in exception: {}", editing_result.exception());
|
||||||
}
|
}
|
||||||
|
|
||||||
EventResult EditingHostManager::handle_return_key(FlyString const& ui_input_type)
|
EventResult EditingHostManager::handle_return_key(FlyString const& ui_input_type)
|
||||||
{
|
{
|
||||||
|
VERIFY(ui_input_type == UIEvents::InputTypes::insertParagraph || ui_input_type == UIEvents::InputTypes::insertLineBreak);
|
||||||
|
|
||||||
// https://w3c.github.io/editing/docs/execCommand/#additional-requirements
|
// https://w3c.github.io/editing/docs/execCommand/#additional-requirements
|
||||||
// When the user instructs the user agent to insert a line break inside an editing host, such as by pressing the
|
// When the user instructs the user agent to insert a line break inside an editing host, such as by pressing the
|
||||||
// Enter key while the cursor is in an editable node, the user agent must call execCommand("insertparagraph") on the
|
// Enter key while the cursor is in an editable node, the user agent must call execCommand("insertparagraph") on the
|
||||||
|
@ -202,19 +197,14 @@ EventResult EditingHostManager::handle_return_key(FlyString const& ui_input_type
|
||||||
// When the user instructs the user agent to insert a line break inside an editing host without breaking out of the
|
// When the user instructs the user agent to insert a line break inside an editing host without breaking out of the
|
||||||
// current block, such as by pressing Shift-Enter or Option-Enter while the cursor is in an editable node, the user
|
// current block, such as by pressing Shift-Enter or Option-Enter while the cursor is in an editable node, the user
|
||||||
// agent must call execCommand("insertlinebreak") on the relevant document.
|
// agent must call execCommand("insertlinebreak") on the relevant document.
|
||||||
auto editing_result = [&] {
|
auto command = ui_input_type == UIEvents::InputTypes::insertParagraph
|
||||||
if (ui_input_type == UIEvents::InputTypes::insertParagraph)
|
? Editing::CommandNames::insertParagraph
|
||||||
return m_document->exec_command(Editing::CommandNames::insertParagraph, false, {});
|
: Editing::CommandNames::insertLineBreak;
|
||||||
if (ui_input_type == UIEvents::InputTypes::insertLineBreak)
|
auto editing_result = m_document->exec_command(command, false, {});
|
||||||
return m_document->exec_command(Editing::CommandNames::insertLineBreak, false, {});
|
|
||||||
VERIFY_NOT_REACHED();
|
|
||||||
}();
|
|
||||||
|
|
||||||
if (editing_result.is_exception()) {
|
if (editing_result.is_exception()) {
|
||||||
dbgln("handle_return_key(): editing resulted in exception: {}", editing_result.exception());
|
dbgln("handle_return_key(): editing resulted in exception: {}", editing_result.exception());
|
||||||
return EventResult::Dropped;
|
return EventResult::Dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
return editing_result.value() ? EventResult::Handled : EventResult::Dropped;
|
return editing_result.value() ? EventResult::Handled : EventResult::Dropped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue