MCPcopy Create free account
hub / github.com/code-with-antonio/nightcode / findActiveMention

Function findActiveMention

packages/cli/src/components/input-bar.tsx:52–92  ·  view source on GitHub ↗
(text: string, cursorOffset: number)

Source from the content-addressed store, hash-verified

50}
51
52function findActiveMention(text: string, cursorOffset: number): MentionMatch | null {
53 const safeOffset = Math.max(0, Math.min(cursorOffset, text.length));
54
55 let start = safeOffset;
56 while (start > 0 && !/\s/.test(text[start - 1]!)) {
57 start -= 1;
58 }
59
60 let end = safeOffset;
61 while (end < text.length && !/\s/.test(text[end]!)) {
62 end += 1;
63 }
64
65 const token = text.slice(start, end);
66 const relativeCursor = safeOffset - start;
67 const mentionStart = token.lastIndexOf("@", relativeCursor);
68
69 if (mentionStart === -1) {
70 return null;
71 }
72
73 const previousCharacter = token[mentionStart - 1];
74 if (previousCharacter && isMentionQueryCharacter(previousCharacter)) {
75 return null;
76 }
77
78 let mentionEnd = mentionStart + 1;
79 while (mentionEnd < token.length && isMentionQueryCharacter(token[mentionEnd]!)) {
80 mentionEnd += 1;
81 }
82
83 if (relativeCursor < mentionStart || relativeCursor > mentionEnd) {
84 return null;
85 }
86
87 return {
88 start: start + mentionStart,
89 end: start + mentionEnd,
90 query: token.slice(mentionStart + 1, mentionEnd),
91 };
92}
93
94async function getMentionCandidates(query: string): Promise<MentionCandidate[]> {
95 const normalizedQuery = query.startsWith("./") ? query.slice(2) : query;

Callers 1

InputBarFunction · 0.85

Calls 1

isMentionQueryCharacterFunction · 0.85

Tested by

no test coverage detected