Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Behavior When Pasting Text in UITextField

Here's what I did:

  1. Open the App Store App
  2. Type in "123" in search box
  3. Cut the text "123" from search box
  4. Type "xx" in search box
  5. Move search box cursor to between both "x"
  6. Paste "123" to search box

The result should be "x123x", but what I get is "x 123 x". This happened on all the UITextField of all apps.

Please refer to this gif: demo

Is this an iOS bug? Or am I missing something here?

like image 203
Lee Kah Seng Avatar asked Oct 17 '22 21:10

Lee Kah Seng


1 Answers

This is intended behavior. There is a property to disable this on iOS 11:

if #available(iOS 11.0, *) {
    textField.smartInsertDeleteType = .no
}

See also: https://developer.apple.com/documentation/uikit/uitextinputtraits/2865828-smartinsertdeletetype?changes=_6

like image 77
José Manuel Sánchez Avatar answered Oct 21 '22 00:10

José Manuel Sánchez