LibWeb: Select contents of <input> when tabbing through fields

Browsers seem to make it convenient to replace an <input>'s contents by
selecting all text on focusing, but only if you used keyboard
navigation. Programmatic focus and clicking on the field do not show
this behavior.
This commit is contained in:
Jelle Raaijmakers 2026-02-10 12:32:47 +01:00 committed by Jelle Raaijmakers
parent dbd09454c4
commit b07a576c22
Notes: github-actions[bot] 2026-02-11 10:28:56 +00:00
4 changed files with 28 additions and 4 deletions

View file

@ -1472,8 +1472,12 @@ void HTMLInputElement::did_receive_focus()
if (m_placeholder_text_node)
m_placeholder_text_node->invalidate_style(DOM::StyleInvalidationReason::DidReceiveFocus);
if (has_selectable_text())
document().get_selection()->remove_all_ranges();
if (has_selectable_text()) {
if (document().last_focus_trigger() == FocusTrigger::Key)
MUST(select());
else
document().get_selection()->remove_all_ranges();
}
}
void HTMLInputElement::did_lose_focus()