diff --git a/lib/shared/typeahead-utils.js b/lib/shared/typeahead-utils.js --- a/lib/shared/typeahead-utils.js +++ b/lib/shared/typeahead-utils.js @@ -20,6 +20,8 @@ selection: Selection, regex: RegExp, ): null | RegExp$matchResult { + // we only try to match if there is end of text or whitespace after cursor + // and when start of selection equals end of selection if ( selection.start === selection.end && (selection.start === text.length || /\s/.test(text[selection.end])) diff --git a/native/chat/chat-input-bar.react.js b/native/chat/chat-input-bar.react.js --- a/native/chat/chat-input-bar.react.js +++ b/native/chat/chat-input-bar.react.js @@ -512,7 +512,6 @@ ); } - // we only try to match if there is end of text or whitespace after cursor let typeaheadRegexMatches = null; if (this.androidPreviousText) { diff --git a/web/chat/chat-input-bar.react.js b/web/chat/chat-input-bar.react.js --- a/web/chat/chat-input-bar.react.js +++ b/web/chat/chat-input-bar.react.js @@ -22,7 +22,10 @@ threadActualMembers, checkIfDefaultMembersAreVoiced, } from 'lib/shared/thread-utils'; -import { getTypeaheadUserSuggestions } from 'lib/shared/typeahead-utils'; +import { + getTypeaheadUserSuggestions, + getTypeaheadRegexMatches, +} from 'lib/shared/typeahead-utils'; import type { TypeaheadMatchedStrings } from 'lib/shared/typeahead-utils'; import type { CalendarQuery } from 'lib/types/entry-types'; import type { LoadingStatus } from 'lib/types/loading-types'; @@ -555,23 +558,17 @@ relativeMemberInfoSelectorForMembersOfThread(props.threadInfo.id), ); - const inputSliceEndingAtCursor = React.useMemo( - () => - props.inputState.draft.slice(0, props.inputState.textCursorPosition), - [props.inputState.draft, props.inputState.textCursorPosition], - ); - // we only try to match if there is end of text or whitespace after cursor const typeaheadRegexMatches = React.useMemo( () => - inputSliceEndingAtCursor.length === props.inputState.draft.length || - /\s/.test(props.inputState.draft[props.inputState.textCursorPosition]) - ? inputSliceEndingAtCursor.match(webTypeaheadRegex) - : null, - [ - inputSliceEndingAtCursor, - props.inputState.textCursorPosition, - props.inputState.draft, - ], + getTypeaheadRegexMatches( + props.inputState.draft, + { + start: props.inputState.textCursorPosition, + end: props.inputState.textCursorPosition, + }, + webTypeaheadRegex, + ), + [props.inputState.textCursorPosition, props.inputState.draft], ); const typeaheadMatchedStrings: ?TypeaheadMatchedStrings = React.useMemo(