@@ -194,15 +194,7 @@ class ReactTextareaAutocomplete extends React.Component {
194194
195195 const textToModify = textareaValue . slice ( 0 , selectionEnd ) ;
196196
197- // It's important to escape the currentTrigger char for chars like [, (,...
198- const findTriggerRegExp = new RegExp ( `\\${ currentTrigger } ${ `[^\\${ currentTrigger } ${ '\\s' } ]` } *` ) ;
199- // reverse the string so we can easily find the first index of the currentTrigger
200- const reversedString = textToModify . split ( '' ) . reverse ( ) . join ( '' ) ;
201- // find the first instance of currentTrigger (-1 if not found)
202- const distanceFromEndOfString = reversedString . search ( findTriggerRegExp ) + 1 ;
203- // if found, distract from the length of the string to revert the position back to an actual string index.
204- const startOfTokenPosition =
205- distanceFromEndOfString === - 1 ? 0 : textToModify . length - distanceFromEndOfString ;
197+ const startOfTokenPosition = textToModify . lastIndexOf ( currentTrigger ) ;
206198
207199 // we add space after emoji is selected if a caret position is next
208200 const newTokenString = newToken . caretPosition === 'next' ? `${ newToken . text } ` : newToken . text ;
@@ -635,12 +627,14 @@ class ReactTextareaAutocomplete extends React.Component {
635627 < SuggestionList
636628 className = { listClassName }
637629 component = { component }
630+ currentTrigger = { currentTrigger }
638631 dropdownScroll = { this . _dropdownScroll }
639632 getSelectedItem = { selectedItem }
640633 getTextToReplace = { textToReplace }
641634 itemClassName = { itemClassName }
642635 itemStyle = { itemStyle }
643636 onSelect = { this . _onSelect }
637+ selectionEnd = { this . state . selectionEnd }
644638 SuggestionItem = { SuggestionItem }
645639 value = { value }
646640 values = { suggestionData }
0 commit comments