Bug 265674 - Updating the caret location in a contenteditable using Selection methods does not cause an update to predictive text
Summary: Updating the caret location in a contenteditable using Selection methods does...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 17
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-12-01 09:05 PST by Jarod Gowgiel
Modified: 2023-12-08 09:06 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jarod Gowgiel 2023-12-01 09:05:04 PST
Steps to reproduce:

* On a device running iOS 17 (real or simulated) open https://codepen.io/JarodG/pen/vYbVveQ
* Using a tap, play around with moving the selection around. Notice that when you move the selection, the "predictive text" and autocorrect bar above the software keyboard is being updated in response to the new selection.
    * For example: placing the caret immediately after the pre-existing word "text" will cause predictive text bar to suggest words like "texting" and "texture"
* Now, tap the button titled "Move selection programmatically"
* Notice: the predictive text bar will keep the same state it had before, and is not updated to reflect the new caret position

Why this matters:

Now that "beforeinput" events are widely available, developers should be able to use these events to create their own bespoke text input handlers. However, on iOS Safari, it's impossible to get reliable behavior from the predictive text bar unless the user is directly interacting with the "contenteditable" div. For software that relies on listening for and consuming keyboard events before they reach the focused input, or those that call "preventDefault" on the "beforeinput" event and handle state changes (including text and selection changes) directly, this bug means that iOS Safari predictive text is permanently out of sync with the actual state of the input.

@wenson_hsieh, I'm including you on the CC list here since you're mentioned in an article I ran into announcing the release of "beforeinput" on Safari (https://webkit.org/blog/7358/enhanced-editing-with-input-events/). The functionality I describe above seems to me like it would be necessary for any web app to properly handle text input specifically for some use cases. I'm also curious if you might have any ideas on workarounds - are there additional events that need to be dispatched for predictive text to update? Are there other standard APIs that should be used to adjust the selection on iOS Safari?
Comment 1 Radar WebKit Bug Importer 2023-12-08 09:06:13 PST
<rdar://problem/119380448>