jessesquires/JSQMessagesViewController — pull request #466 by ghazel (2014-09-03 01:01:24+00:00)
Title: accept autocorrect by resigning/becoming first responder

The strategy of adding a space and then trimming it was causing an indefinite hang with some strange strings. Reproducible with a ridiculous example like:

ȗ̷͓͍̭͉̖͎̙̹̱͙̝̥̥̣͍͆͛͋ͨ̄̑́́̕n͋́̏͊̄̏̾̈́̀̔̓ͥ͑ͦ̆̔ͬ҉̢͉͓͖͕͔͎͎͙̹͘i̴̧̡̳̱̺̪̘̲͖̠̙̭̅ͮ̀́ͮͯ̀̾͂͊͒̎̚̚͡͝c̓̓̈͂͊̈́͛̃̃ͫ͂̇ͫͫͣͧ͗̚͏̜͈̥̳̜̖͔̥̕͜ͅo̸̧̯̤̺͓͇̭̮͕̜̫͈̲̫͇̫̊͑̊ͤͪͫͩͨ̀̕͝ͅd̸̲̯͇̲̻̣̼͚̳̖̗̣̫̭̼̼̞͈ͩ̈̃̈̅̚͘͝͞ė̇̌ͩ̔͋̏ͣͮͪͦ͌ͤ̾̒̋͑̕҉̛̮̲͈̱̥̲

(isn't unicode great?)

Anyway, resigning and becoming the first responder seems to be another accepted approach for accepting auto-correct, and it works to avoid this hang as well. Probably better than mucking with the string.