I'm trying to implement my own UITextInput however I'm having trouble updating the position using the cursor key on a Bluetooth keyboard. I'm trying to create a TextInput that loops, if you imagine the characters being numbered like this:
1 2 3
4 5 6
7 8 9
Then pressing up at position 2, should take you to position 8 (pressing left on 6 takes you to 4 etc). iOS seems to call positionFromPosition:inDirection:offset: to figure how where to move from the current position. It then calls setSelectedTextRange: to update the cursor position.
This is fine so far, but it seem that sometimes iOS DOESN'T call positionFromPosition:inDirection:offset: for example if I press Up and then Down again, iOS appears to cache the previous position and just call setSelectedTextRange: with that previous value. I don't understand this, is there a way of telling iOS that the selected position has changed and it should clear it's cache, i.e. if someone presses a "clear" button or something?
The caching ONLY seems to occur for Up and Down cursor key presses, moving left and right never caches previous values and positionFromPosition:inDirection:offset: is always called. Even if I don't consider the possibility of something reseting the cursor position I still have issues with "positionFromPosition:inDirection:offset:" not being called occasionally, and I just keep getting "setSelectedTextRange:" set to the same value by iOS. So if feels like there's something I've misunderstood about how iOS is caching cursor movement. Can anyone help me out?