servoshell: Select address bar text on click (#37839)

In Firefox, clicking on the address bar selects all the text. This makes
Servo to do the same. I reworked the code so that the shortcut only
changes the focus. That means that either clicking or the shortcut
changes the focus which in turn selects the text.

Testing: I tested it manually by clicking in the address bar and using
the shortcuts and noticing that the text was selected.

Signed-off-by: Michael Mc Donnell <michael@mcdonnell.dk>
This commit is contained in:
Michael Mc Donnell 2025-07-03 10:04:02 -04:00 committed by GitHub
parent ca47cc2fa3
commit e3baec4807
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -340,7 +340,11 @@ impl Minibrowser {
i.clone().consume_key(Modifiers::ALT, Key::D)
}
}) {
// The focus request immediately makes gained_focus return true.
location_field.request_focus();
}
// Select address bar text when it's focused (click or shortcut).
if location_field.gained_focus() {
if let Some(mut state) =
TextEditState::load(ui.ctx(), location_id)
{
@ -352,6 +356,7 @@ impl Minibrowser {
state.store(ui.ctx(), location_id);
}
}
// Navigate to address when enter is pressed in the address bar.
if location_field.lost_focus() &&
ui.input(|i| i.clone().key_pressed(Key::Enter))
{