Add live search to autocomplete and only highlight known handles

This commit is contained in:
Paul Frazee 2022-11-17 14:35:12 -06:00
parent 859087f21d
commit 2b98714548
6 changed files with 138 additions and 40 deletions

View file

@ -57,11 +57,17 @@ export function ago(date: number | string | Date): string {
}
}
export function extractEntities(text: string): Entity[] | undefined {
export function extractEntities(
text: string,
knownHandles?: Set<string>,
): Entity[] | undefined {
let match
let ents: Entity[] = []
const re = /(^|\s)(@)([a-zA-Z0-9\.-]+)(\b)/dg
while ((match = re.exec(text))) {
if (knownHandles && !knownHandles.has(match[3])) {
continue // not a known handle
}
ents.push({
type: 'mention',
value: match[3],