Page MenuHomePhabricator

D6047.diff
No OneTemporary

D6047.diff

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(
`(?<textPrefix>(?:^(?:.|\n)*\\s+)|^)@(?<username>${oldValidUsernameRegexString})?$`,
@@ -71,14 +70,26 @@
caretLeftOffset,
};
}
+export type GetTypeaheadTooltipActionsParams = {
+ +inputStateDraft: string,
+ +inputStateSetDraft: (draft: string) => mixed,
+ +inputStateSetTextCursorPosition: (newPosition: number) => mixed,
+ +suggestedUsers: $ReadOnlyArray<RelativeMemberInfo>,
+ +textBeforeAtSymbol: string,
+ +usernamePrefix: string,
+};
function getTypeaheadTooltipActions(
- inputState: InputState,
- textarea: HTMLTextAreaElement,
- suggestedUsers: $ReadOnlyArray<RelativeMemberInfo>,
- textBeforeAtSymbol: string,
- usernamePrefix: string,
+ params: GetTypeaheadTooltipActionsParams,
): $ReadOnlyArray<TypeaheadTooltipAction> {
+ 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,
);
},

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 9:47 PM (21 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577415
Default Alt Text
D6047.diff (3 KB)

Event Timeline