mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-04 16:46:08 +00:00
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:
parent
6a0c67d5d2
commit
7ae7e3eef3
Notes:
github-actions[bot]
2024-09-05 13:39:06 +00:00
Author: https://github.com/trflynn89
Commit: 7ae7e3eef3
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1284
Reviewed-by: https://github.com/tcl3 ✅
1 changed files with 11 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue