Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/typeahead-utils.js
Show All 20 Lines | ): $ReadOnlyArray<RelativeMemberInfo> { | ||||
return usersInThread | return usersInThread | ||||
.filter(user => usernamePrefix.length === 0 || userIDs.includes(user.id)) | .filter(user => usernamePrefix.length === 0 || userIDs.includes(user.id)) | ||||
.sort((userA, userB) => | .sort((userA, userB) => | ||||
stringForUserExplicit(userA).localeCompare(stringForUserExplicit(userB)), | stringForUserExplicit(userA).localeCompare(stringForUserExplicit(userB)), | ||||
); | ); | ||||
} | } | ||||
export { getTypeaheadUserSuggestions }; | function getNewTextAndSelection( | ||||
textBeforeAtSymbol: string, | |||||
entireText: string, | |||||
usernamePrefix: string, | |||||
user: RelativeMemberInfo, | |||||
): { | |||||
newText: string, | |||||
newSelectionStart: number, | |||||
} { | |||||
const totalMatchLength = | |||||
textBeforeAtSymbol.length + usernamePrefix.length + 1; // 1 for @ char | |||||
let newSuffixText = entireText.slice(totalMatchLength); | |||||
newSuffixText = (newSuffixText[0] !== ' ' ? ' ' : '') + newSuffixText; | |||||
const newText = | |||||
textBeforeAtSymbol + '@' + stringForUserExplicit(user) + newSuffixText; | |||||
const newSelectionStart = newText.length - newSuffixText.length + 1; | |||||
return { newText, newSelectionStart }; | |||||
} | |||||
export { getTypeaheadUserSuggestions, getNewTextAndSelection }; |