/** * Given the current textarea value and cursor position, returns the * @-person-mention query being typed (the text after the last triggering @), * or null if no person-mention is active. * * Rules — distinct from comment-mentions in `mention.ts`: * - @ must be at the start of the string or preceded by whitespace * - The query may contain spaces (historical persons commonly have multi-word * display names — "Auguste Raddatz", "Maria von Müller-Schultz") * - The query stops at a newline or at a second @ (the next mention starts) */ export function detectPersonMention(text: string, cursorPos: number): string | null { const before = text.slice(0, cursorPos); const atIndex = before.lastIndexOf('@'); if (atIndex === -1) return null; if (atIndex > 0 && !/\s/.test(before[atIndex - 1])) return null; const query = before.slice(atIndex + 1); if (query.includes('\n') || query.includes('@')) return null; return query; }