Add live search to autocomplete and only highlight known handles
This commit is contained in:
parent
859087f21d
commit
2b98714548
6 changed files with 138 additions and 40 deletions
|
@ -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],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue