manishkkatoch / SimpleTwoWayBindingIOS

An ultra light, ultra simple two way binding library for IOS and Swift.
MIT License
165 stars 48 forks source link

UITextField and UITextView don't behave well with some unicode #15

Open fweez opened 4 years ago

fweez commented 4 years ago

The updateValue methods in the UITextField and UITextView appear to be tickling a UIKit bug, causing the cursor to unexpectedly jump to the end of the text field while editing.

  1. In the example app, enter some text with a double-width unicode character, such as 🍕 , in the middle. For instance, I entered "Ryan 🍕 Forsythe".
  2. Move the cursor back to the middle of the text. For instance, I moved the cursor to just after the "n" character.
  3. Type any character or hit the backspace
  4. That character appears at the cursor, but then the cursor immediately jumps to the end of the text field.

This repro is for UITextField, but we're seeing the same issue in UITextView. If the whole text field is single-width characters (the ASCII region of unicode works for this) this bug doesn't happen, so I assume this is actually a bug in UIKit. The fix is pretty easy, though. I've forked and made the change, and will send a PR referencing this issue.