Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Understanding positionFromPosition:inDirection:offset:
    primarykey
    data
    text
    <p>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:</p> <pre><code>1 2 3 4 5 6 7 8 9 </code></pre> <p>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.</p> <p>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?</p> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload