WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
244976
Textarea selection does not return the caret position on focus event
https://bugs.webkit.org/show_bug.cgi?id=244976
Summary
Textarea selection does not return the caret position on focus event
Ahmad Saleem
Reported
2022-09-09 07:03:18 PDT
Hi Team, Another dumpster dive in Chromium Monorail to find any test case broken in Safari / Webkit and I came across following: Test Case -
https://jsfiddle.net/2s64xjve/
---- <textarea id="text"></textarea> <button onclick="document.getElementById('text').focus();">Focus</button> <script> var textarea = document.getElementById('text'); textarea.addEventListener('focus', function (e) { console.log(textarea.selectionStart); }); </script> ---- Chrome Bug Link -
https://crbug.com/526516
*** STEPS TO REPRODUCE *** 1) Go to JSFiddle 2) Type something in the field 3) Place your cursor in the middle or somewhere in the text and click on "Focus" <<< ACTUAL RESULT >>> Returns 0 <<< EXPECTED RESULT >>> Show the caret position or character where our IBEAM cursor is. ^^^ OTHER BROWSERS ^^^ Chrome Canary 107 - shows position of IBEAM Firefox Nightly 106 - shows position of IBEAM Safari Technology Preview 152 - shows "Actual Result" _____ Matching other browsers would be great and why not another chance to make Webkit better. Thanks!
Attachments
Add attachment
proposed patch, testcase, etc.
Ryosuke Niwa
Comment 1
2022-09-11 11:11:42 PDT
Hm... Chrome also seems to fail this test. Only Firefox shows the right offset when clicking inside the textarea.
Alexey Proskuryakov
Comment 2
2022-09-11 13:57:57 PDT
In my testing, Chrome passes? I think that there are two aspects here: 1. Why are we even removing the focus from textarea when clicking on the button? Seems related to
bug 22261
. 2. When the focus returns, the selection is restored too late. Compare to this test case: textarea.addEventListener('focus', function (e) { console.log(textarea.selectionStart); // 0 setTimeout(()=>{console.log(textarea.selectionStart)}, 0); // correct offset });
Radar WebKit Bug Importer
Comment 3
2022-09-16 07:04:17 PDT
<
rdar://problem/100025436
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug