LibWeb: Limit select-all actions to editable nodes when they are focused

If the user presses ctrl+a inside an <input> element, for example, we
now select that element's text only.
This commit is contained in:
Timothy Flynn
2024-09-04 11:29:38 -04:00
committed by Tim Ledbetter
parent 6a0c67d5d2
commit 7ae7e3eef3

View File

@@ -2147,13 +2147,20 @@ void Navigable::select_all()
auto document = active_document();
if (!document)
return;
auto* body = document->body();
if (!body)
return;
auto selection = document->get_selection();
if (!selection)
return;
(void)selection->select_all_children(*document->body());
if (auto position = document->cursor_position(); position && position->node()->is_editable()) {
auto& node = *position->node();
auto node_length = node.length();
(void)selection->set_base_and_extent(node, 0, node, node_length);
document->set_cursor_position(DOM::Position::create(document->realm(), node, node_length));
} else if (auto* body = document->body()) {
(void)selection->select_all_children(*body);
}
}
void Navigable::paste(String const& text)