(text: string, position: number)
| 365 | } |
| 366 | |
| 367 | export 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 | } |
no outgoing calls
no test coverage detected