Bug 218890

Summary: REGRESSION (iOS 14): window.getSelection().getRangeAt(0) on iOS 14 WKWebView returns an incorrect startOffset
Product: WebKit Reporter: xiehaiyan_xhy
Component: HTML EditingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: darin, megan_gardner, rniwa, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: iPhone / iPad   
OS: Other   

Description xiehaiyan_xhy 2020-11-13 01:08:41 PST
In iOS 13 WKWebview and other browsers such as Chrome, when call window.getSelection().getRangeAt(0), it will return the tap character index.
But on iOS 14 WKWebview, window.getSelection().getRangeAt(0) doesn't return character index, but seems to return a word end index in en language.

My question is:
Can we fix this to keep the same as other browsers and iOS 13 WKWebView?

Details as below:

Code:
document.addEventListener('click', (event) => { 
    var range = window.getSelection().getRangeAt(0);
    console.log("startOffset: "+ range.startOffset.toString());
});

Test case 1: 
Action: There is a sentence in website as "Test click on website", click at the end of "e" in "Test".
Output: 
In iOS 13 WKWebview and other browsers:     startOffset: 2
In iOS 14 WKWebview:      startOffset: 5


Also in iOS 14 WKWebview the word ending rule is not the same, when click on the first word in the node, return index will include whitespace, as we see in test case 1.

But some others return index which not include whitespace as Test case 2.

Test case 2:
There is a sentence in website as "Test click on website", tap at the end of "l" in "click"
Output: 
In iOS 13 WKWebview and other browsers:     startOffset: 7
In iOS 14 WKWebview:      startOffset: 10
Comment 1 Radar WebKit Bug Importer 2020-11-14 11:54:36 PST
<rdar://problem/71403777>
Comment 2 Darin Adler 2020-11-15 15:40:15 PST
Oh no, this sounds like a bad regression. I assume I caused it with my work on the Selection API. Can we make a regression test to demonstrate? I’m really surprised we didn’t have a test.
Comment 3 xiehaiyan_xhy 2020-11-15 22:19:46 PST
Thanks a lot to look into this, Darin! Could you kindly share when the fix will be released to iOS? Thanks!
Comment 4 xiehaiyan_xhy 2020-11-15 22:20:35 PST
And it would be great to regress in other languages besides en, thanks!
Comment 5 Darin Adler 2020-11-16 09:55:40 PST
I’m not looking into it at this time. Just commented. I am inviting someone to help out by creating a regression test.
Comment 6 Darin Adler 2020-11-16 09:58:43 PST
Also would be good to know if anyone has examples of websites affected.