Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3357288
D6047.id20388.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D6047.id20388.diff
View Options
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) => void,
+ +inputStateSetTextCursorPosition: (newPosition: number) => void,
+ +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
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 11:23 PM (20 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2577607
Default Alt Text
D6047.id20388.diff (3 KB)
Attached To
Mode
D6047: [web] Keyboard support for typeahead [7/13] - Refactor getTypeaheadTooltipActions using params as argument
Attached
Detach File
Event Timeline
Log In to Comment