webscopeio / react-textarea-autocomplete

📝 React component implements configurable GitHub's like textarea autocomplete.
MIT License
451 stars 80 forks source link

Popup not triggered if the trigger character is attached to text containing another trigger. #62

Closed coniel closed 6 years ago

coniel commented 6 years ago

The popup is not triggered when there is no space between the typed trigger and other text which already includes a trigger. It works fine if I omit the @ symbol from the inserted text. However, I need to keep the @ symbol in the inserted text as it is used later to find variables in the text and replace them with their values.

I tried reading through the code but couldn't figure out what would cause this behaviour.

Here's a gif demonstrating the problem: popup not triggered

jukben commented 6 years ago

Hey! I don't think it's problem in RTA. Could you please provide repro. Easiest would be use this CodePen https://codepen.io/jukben/pen/bYZqvR as start.

What I'm thinking is about is that you return an empty array in [] from the provider, because you are seeking for @}. Could you please check it?

Anyway, thanks for this issues. I'm going to help you as much as possible!

coniel commented 6 years ago

It is indeed returning []. However, when I write something like in the gif:

\frac{@foo}{@}

it's not seeking @} but it's seeking foo}{@}. Basically, the RegEx is finding the wrong @.

Here's a pen showing basically how I use it: https://codepen.io/anon/pen/LmWbNQ

Thank you so much for the help btw!

jukben commented 6 years ago

I see. 👍 That's actually another feature. Your use case is very specifics so I'm wondering how to solve it properly. This component is build to follow trigger point to the end of the word but in your case, it might be good to have some "boundaries" set, not sure how, though.

Do you have any idea what would you expect? Reset the trigger when another trigger is typed – @first@second - in current implementation output functor get first@second, with the new one it will get the second. That would make sense, probably. The only disadvantage is that you can't get token with the same char as the actual trigger point.

jukben commented 6 years ago

I will try to enhance the behavior for your use-case as a part of #61. It's quite huge change, though. But I hope it should be possible to solve it. Stay tuned. 👍

teilzeitgeist commented 5 years ago

I think I have a similar problem:

I wanna use it in a project but there is an requirement named "Group mentions", which means besides the known "@user" autocomplete there is also an "@@group" feature.

So I have two triggers: "@" and "@@". My problem is that since "@" is triggered, the trigger of "@@" only fires once and than after another char never again.

Here you can finde the example code: https://codesandbox.io/embed/8x9qww899l

jukben commented 5 years ago

@Psyphant Thanks for the reporting! I've just released new version which fixing this behavior. (Let's move hypothetical discussion into #145 )

teilzeitgeist commented 5 years ago

@Psyphant Thanks for the reporting! I've just released new version which fixing this behavior. (Let's move hypothetical discussion into #145 )

@jukben I have to thank! That was an incredible fast fix 👍