Issues with Scribble on a custom UITextInput view

Hi,

I have a custom UITextInput view implementing all the methods (I guess) of UITextInput.

I'm also using a custom UITextInputStringTokenizer subclass, but the issue it the same with a bare UITextInputStringTokenizer: whatever I'm trying to select, the interaction selects the whole sentence, or some sub-sentence, but never the word. The same if I strike through, or try to insert or delete a space.

I'm seeing the tokenizer being asked for sentences ranges, but never words. In an off the shelf UITextView, I'm seeing the same ranges being asked, and then a convergence with requests for words ranges. It never happens in my view.

I'm quite sure the "positions for point" that I'm returning are correct, as well as the tokenizer's responses. If I'm using my finger, everything is fine.

In other words, scribble interaction fails to identify the range to act on, and always find a range that is bigger than it should be.

If I draw slowly to the right, sometime I see the selection handle position move ~5cm farther than the pencil to the right. If draw slowly to the left, the same, with the handle ~5cm farther to the left.

Does anyone has the same issue? This renders scribble unusable in my view. This is for iOS 14 beta 1 on a 10.5 iPad Pro with the 1st generation Pencil. The issue happens whereas I'm installing myself an UIScribbleInteraction or do nothing and let the system do this itself on UITextInput apparently.

Thanks in advance.
Thomas

Answered by RabugenTom in 620488022
It turns out that my firstRectForRange(for:) function was returning the whole line fragment containing the range. Since I don't use autocorrection in my view, this method is not called usually and I missed the issue.
The scribble interaction calls this method internally. Once returning the correct values, it works like a charm!

Accepted Answer
It turns out that my firstRectForRange(for:) function was returning the whole line fragment containing the range. Since I don't use autocorrection in my view, this method is not called usually and I missed the issue.
The scribble interaction calls this method internally. Once returning the correct values, it works like a charm!

Issues with Scribble on a custom UITextInput view
 
 
Q