1

When you double tap on a UITextView, it will by default select the closest word which generally works fine. The problem is that if my textview contains something such as:

SELECT * FROM my_table

and you double tap on the table part of my_table, only table will be selected, however I want to select the entire my_table string.

I can fix this myself by adding a UITapGestureRecognizer and handling double taps, detecting ranges myself and selecting the range myself, however I was wondering if there was anything I could override on UITextView to handle this case (for example macOS has a doubleClickAtIndex method which can be overridden to handle this exact case.

Kyle
  • 17,317
  • 32
  • 140
  • 246
  • Maybe `textViewDidChangeSelection:`? Or maybe with this: https://stackoverflow.com/questions/18704692/detect-character-tapped-in-uitextview and the `rangeEnclosingPosition:withGranularity:inDirection:`, but not sure if word granularity considered with underscore. – Larme Nov 29 '17 at 16:17
  • I think if I customize UITextInputTokenizer -> rangeEnclosingPosition to include underscores for word granularity that should do the trick for me! I'll give it a shot. – Kyle Nov 29 '17 at 16:23
  • 1
    Based on your tip I was able to get it working. A first draft is here: https://pastebin.com/2jsUAB7t -- Probably a few bugs, as I haven't tested all to far yet. – Kyle Nov 29 '17 at 17:18
  • Great if it seems to work. Do not forget to post an answer when it's "fully" done ;) – Larme Nov 29 '17 at 17:19

0 Answers0