UITextViewDelegate.textView(_:shouldChangeTextIn:replacementText:) is called with wrong range by back deletion from custom keyboard

Originator:an00na
Number:rdar://48073321 Date Originated:February 14 2019, 9:11 AM
Status:Open Resolved:
Product:iOS + SDK Product Version:12.2
Classification:Serious Bug Reproducible:Always
 
Area:
UIKit

Summary:
When custom keyboard calls UIInputViewController.textDocumentProxy.deleteBackward() to delete backward 1 character, UITextViewDelegate.textView(_:shouldChangeTextIn:replacementText:) is called with NSRange of length 1 regardless of the character's composition and UTF16 encoding length. For example, deleting 😃 should have a NSRange of length 2.

In contrast, system keyboards give the correct NSRange.


Steps to Reproduce:
1. Launch sample app.
2. Install the embedded custom keyboard in system Settings.
3. Use the custom keyboard to delete the emojis. Read the console logs to see the NSRange with length 1.
4. Relaunch the app.
5. Use system keyboard to delete the emojis. Read the console logs to see the NSRange with length 2.


Code: https://mega.nz/#!5PY2HITJ!Lzq_eLttSERMgVx9Sz91GPOlSdUuqO62ujAsr7zZzoo

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!