Mentions plugin breaks after manipulating text programmatically
Hello, I am currently trying to append a space after a mention programmatically. I'm using the code below to accomplish this, for simplicity sake I'm assuming the mention is being added to the end of the text.
func mentionsPlugin(_ plugin: HKWMentionsPlugin!, createdMention entity: HKWMentionsEntityProtocol!, atLocation location: UInt) {
// capture existing mentions
let mentions = plugin.mentions()
// append a space, this will cause the mentions plug in to lose it's mentions
textView.text.append(" ")
// add the captured mentions back to the plugin
plugin.addMentions(mentions)
//inform the plugin that we have updated the textview programatically
plugin.textViewDidProgrammaticallyUpdate(textView)
}
If the next character that is typed is a control character mentionsPlugin(_ plugin: HKWMentionsPlugin!, stateChangedTo newState: HKWMentionsPluginState, from oldState: HKWMentionsPluginState) is called twice in rapid succession once with a newState of .creatingMention and then with a newState of .quiescent. The chooser view is never presented, and the mentionsPluginWillActivateChooserView and mentionsPluginActivatedChooserView delegate methods are never called.
if the control character is deleted, a space typed, or any other characters are typed before the initial control character the chooser view is presented as expected.
Yea, this messes with the state machine quite a bit. What if you try adding the mention after didProgramaticallyUpdate? I don't know exactly how this is breaking or how to fix, but we'll take a look eventually.