MCPcopy Create free account
hub / github.com/dailydotdev/apps / checkMention

Function checkMention

packages/shared/src/hooks/input/useMarkdownInput.ts:370–408  ·  view source on GitHub ↗
(position?: number[])

Source from the content-addressed store, hash-verified

368 * @see https://linear.app/dailydotdev/issue/ENG-228
369 */
370 const checkMention = (position?: number[]) => {
371 const current = [textarea.selectionStart, textarea.selectionEnd];
372 const selection = position ?? current;
373 const [word] = getCloseWord(textarea, selection);
374 const mention = word.substring(1);
375 const isValid =
376 word.charAt(0) === '@' &&
377 (mention.length === 0 || handleRegex.test(mention));
378
379 if (!isValid) {
380 return updateQuery(undefined);
381 }
382
383 // Skip mention detection if @ is inside a markdown link
384 if (isSelectionInMarkdownLink(textarea, selection[0], selection[1])) {
385 return updateQuery(undefined);
386 }
387
388 // Skip mention detection if @ is part of a URL
389 // Check if the word containing @ is a URL (with or without protocol)
390 // This regex matches:
391 // - URLs starting with www.
392 // - URLs with http:// or https://
393 // - Domain-like patterns (e.g., example.com, sub.domain.com)
394 const looksLikeUrl =
395 isValidHttpUrl(word) ||
396 word.startsWith('www.') ||
397 /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+/i.test(word);
398
399 if (looksLikeUrl) {
400 return updateQuery(undefined);
401 }
402
403 if (isNullOrUndefined(query)) {
404 return updateQuery(mention ?? '');
405 }
406
407 return updateQuery(mention);
408 };
409
410 const checkEmoji = (position?: number[]) => {
411 const current = [textarea.selectionStart, textarea.selectionEnd];

Callers 3

onInputClickFunction · 0.85
onKeyUpFunction · 0.85
onInputFunction · 0.85

Calls 5

getCloseWordFunction · 0.90
isValidHttpUrlFunction · 0.90
isNullOrUndefinedFunction · 0.90
updateQueryFunction · 0.85

Tested by

no test coverage detected