MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / shouldShowContextMenu

Function shouldShowContextMenu

webview-ui/src/utils/context-mentions.ts:367–397  ·  view source on GitHub ↗
(text: string, position: number)

Source from the content-addressed store, hash-verified

365}
366
367export function shouldShowContextMenu(text: string, position: number): boolean {
368 const beforeCursor = text.slice(0, position)
369
370 // Check if we're in a slash command context (at the beginning and no space yet)
371 if (text.startsWith("/") && !text.includes(" ") && position <= text.length) {
372 return true
373 }
374
375 // Check for @ mention context
376 const atIndex = beforeCursor.lastIndexOf("@")
377
378 if (atIndex === -1) {
379 return false
380 }
381
382 const textAfterAt = beforeCursor.slice(atIndex + 1)
383
384 // Check if there's any unescaped whitespace after the '@'
385 // We need to check for whitespace that isn't preceded by a backslash
386 // Using a negative lookbehind to ensure the space isn't escaped
387 const hasUnescapedSpace = /(?<!\\)\s/.test(textAfterAt)
388 if (hasUnescapedSpace) return false
389
390 // Don't show the menu if it's clearly a URL
391 if (textAfterAt.toLowerCase().startsWith("http")) {
392 return false
393 }
394
395 // Show menu in all other cases
396 return true
397}

Callers 2

ChatTextArea.tsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected