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.

4
  • Maybe textViewDidChangeSelection:? Or maybe with this: stackoverflow.com/questions/18704692/… and the rangeEnclosingPosition:withGranularity:inDirection:, but not sure if word granularity considered with underscore. Commented Nov 29, 2017 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. Commented Nov 29, 2017 at 16:23
  • 1
    Based on your tip I was able to get it working. A first draft is here: pastebin.com/2jsUAB7t -- Probably a few bugs, as I haven't tested all to far yet. Commented Nov 29, 2017 at 17:18
  • Great if it seems to work. Do not forget to post an answer when it's "fully" done ;) Commented Nov 29, 2017 at 17:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.