diff --git a/web/chat/typeahead-tooltip.react.js b/web/chat/typeahead-tooltip.react.js --- a/web/chat/typeahead-tooltip.react.js +++ b/web/chat/typeahead-tooltip.react.js @@ -38,14 +38,22 @@ const actions = React.useMemo( () => - getTypeaheadTooltipActions( - inputState, - textarea, + getTypeaheadTooltipActions({ + inputStateDraft: inputState.draft, + inputStateSetDraft: inputState.setDraft, + inputStateSetTextCursorPosition: inputState.setTextCursorPosition, suggestedUsers, textBeforeAtSymbol, usernamePrefix, - ), - [inputState, textarea, suggestedUsers, textBeforeAtSymbol, usernamePrefix], + }), + [ + inputState.draft, + inputState.setDraft, + inputState.setTextCursorPosition, + suggestedUsers, + textBeforeAtSymbol, + usernamePrefix, + ], ); const tooltipPosition = React.useMemo( diff --git a/web/utils/typeahead-utils.js b/web/utils/typeahead-utils.js --- a/web/utils/typeahead-utils.js +++ b/web/utils/typeahead-utils.js @@ -7,7 +7,6 @@ import type { RelativeMemberInfo } from 'lib/types/thread-types'; import { typeaheadStyle } from '../chat/chat-constants'; -import { type InputState } from '../input/input-state'; const webTypeaheadRegex: RegExp = new RegExp( `(?(?:^(?:.|\n)*\\s+)|^)@(?${oldValidUsernameRegexString})?$`, @@ -71,14 +70,26 @@ caretLeftOffset, }; } +export type GetTypeaheadTooltipActionsParams = { + +inputStateDraft: string, + +inputStateSetDraft: (draft: string) => void, + +inputStateSetTextCursorPosition: (newPosition: number) => void, + +suggestedUsers: $ReadOnlyArray, + +textBeforeAtSymbol: string, + +usernamePrefix: string, +}; function getTypeaheadTooltipActions( - inputState: InputState, - textarea: HTMLTextAreaElement, - suggestedUsers: $ReadOnlyArray, - textBeforeAtSymbol: string, - usernamePrefix: string, + params: GetTypeaheadTooltipActionsParams, ): $ReadOnlyArray { + const { + inputStateDraft, + inputStateSetDraft, + inputStateSetTextCursorPosition, + suggestedUsers, + textBeforeAtSymbol, + usernamePrefix, + } = params; return suggestedUsers .filter( suggestedUser => stringForUserExplicit(suggestedUser) !== 'anonymous', @@ -91,7 +102,7 @@ const totalMatchLength = textBeforeAtSymbol.length + usernamePrefix.length + 1; // 1 for @ char - let newSuffixText = inputState.draft.slice(totalMatchLength); + let newSuffixText = inputStateDraft.slice(totalMatchLength); newSuffixText = (newSuffixText[0] !== ' ' ? ' ' : '') + newSuffixText; const newText = @@ -100,8 +111,8 @@ stringForUserExplicit(suggestedUser) + newSuffixText; - inputState.setDraft(newText); - inputState.setTextCursorPosition( + inputStateSetDraft(newText); + inputStateSetTextCursorPosition( newText.length - newSuffixText.length + 1, ); },