From 3c4ec171801c93eccf209f08fc01f201d57f73e7 Mon Sep 17 00:00:00 2001 From: webbeef Date: Fri, 11 Apr 2025 13:24:16 -0700 Subject: [PATCH] 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 --- components/script/dom/htmlinputelement.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 9da0bd4e6c3..e12ad21631a 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -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::().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::().dirty(NodeDamage::OtherNodeDamage); + event.PreventDefault(); } } }