textinput: position the caret at the end when selecting input (#36478)

When clicking on a text input element, we currently position the caret
at the very beginning, even if there is already text present. That makes
is annoying when you want to add text, and doesn't match what other
browsers do.
Instead, this change positions the caret at the end of the current text.

Testing: Not covered by any wpt tests (rightly so I think).

Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
webbeef 2025-04-11 13:24:16 -07:00 committed by GitHub
parent fc2eb7bff2
commit 3c4ec17180
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2647,12 +2647,18 @@ impl VirtualMethods for HTMLInputElement {
point_in_target,
CanGc::note(),
);
if let Some(i) = index {
self.textinput.borrow_mut().set_edit_point_index(i);
// trigger redraw
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.PreventDefault();
}
// Position the caret at the click position or at the end of the current
// value.
let edit_point_index = match index {
Some(i) => i,
None => self.textinput.borrow().char_count(),
};
self.textinput
.borrow_mut()
.set_edit_point_index(edit_point_index);
// trigger redraw
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
event.PreventDefault();
}
}
}