webscopeio / react-textarea-autocomplete

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

Multiple triggers not working without space separation #100

Closed guido-visser closed 5 years ago

guido-visser commented 5 years ago

I have a scenario where I want to autocomplete a certain syntax. The idea is that there are no spaces in this syntax. I've created a Code Pin with the scenario: https://codepen.io/dagorbattle/pen/NEgBdQ I'd like to auto complete the following: [country.id]

According to the code, when starting to type [ it should show: 'country' and 'person'. After the insert, when I type a . I'd like it to open the . trigger. Instead, it continues to look for values that belongs to the first trigger, unless a space is in between the 2 triggers.

Is there a way to use 2 triggers in the same string without using spaces in between the inserts?

Also, when using caretPosition: "end", the autocomplete box doesn't disappear when pressing Enter/Tab.

The completion works correctly when using caretPosition: "next", but the spaces are not wanted within the syntax.

jukben commented 5 years ago

Hi, thanks for the issue.

There are two things:

1)

Also, when using caretPosition: "end", the autocomplete box doesn't disappear when pressing Enter/Tab.

This is a bug - reggresion I guess made it somewhere between the latest versions.

2)

The idea is that there are no spaces in this syntax.

Sometimes you want that behavior, sometimes not. I guess I need to figure out some API how to allow this kind of "interfering" behavior. Not sure, maybe it would be possible to write something like

trigger={{
        "[": {
          dataProvider: token => {
            return [
              {name: 'country'},
              {name: 'person'}
            ];
          },
          allowInterfering: true,
          component: Item,
          output: (item, trigger) => { return {text: `${trigger}${item.name}`, caretPosition: "end" }
        }
...

this would match also the other triggers if there will be a match, even without spaces. The trigger will seamlessly jump to the other one. What do you think about this?

guido-visser commented 5 years ago

Hi,

It would be great if the first issue could be resolved. For the second one, your suggestion seems good.

Thanks for the quick reply!