devopsinthecloud icon indicating copy to clipboard operation
devopsinthecloud copied to clipboard

Mentions plugin breaks after manipulating text programmatically

Open KrisConrad opened this issue 7 years ago • 1 comments

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.

KrisConrad avatar Nov 29 '18 20:11 KrisConrad

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.

dgattey avatar Mar 01 '19 08:03 dgattey