RoleModel/RMSTokenView — pull request #7 by kilink (2014-05-05 19:44:18+00:00)
Title: Add support for placeholder text

This PR adds support for placeholder text, as discussed in issue #5.

I took a different route than what was suggested there because the textField would not display the placeholder text if it contained the invisible backspace characters.

While this turned into a larger set of changes than I anticipated, I think I was able to simplify some of the code along the way.

To detect pressing of the backspace button, I created a UITextField subclass that informs a delegate when when text was deleted (e.g., backspace was pressed). This triggers even when the text doesn't change, like when the textField is empty, and therefore avoids the need to add invisible characters. This allowed me to get rid of a lot of the code that was dealing with detecting backspaces and fixing up selection ranges, etc.

The one tricky aspect was that I only want the placeholder text to be displayed when the text field is empty AND when there are no tokens. To make that work, I added a new placeholder property to the TokenView, and toggle the textField's placeholder property depending on whether there are currently any tokens.