fix(desktop): only show slash popover when / is first char

The SLASH_TRIGGER_RE regex used (?:^|[\s]) as its left anchor, so typing
a / anywhere in the message (e.g. "hello /") opened the slash command
popover — even though slash commands only execute at the beginning of a
message. Anchor the regex strictly at position 0 (^) so the popover only
appears when / is the first character, matching the actual execution
semantics. The @-mention trigger is left untouched since those work
anywhere in the text.
This commit is contained in:
ethernet 2026-07-10 13:24:40 -04:00
parent b8880f1245
commit f7c9feb395
2 changed files with 13 additions and 1 deletions

View file

@ -46,6 +46,14 @@ describe('detectTrigger', () => {
expect(detectTrigger('/path/to/file')).toBeNull()
})
it('does not trigger slash popover mid-message', () => {
expect(detectTrigger('hello /')).toBeNull()
expect(detectTrigger('hello /skill')).toBeNull()
expect(detectTrigger('hello there /personality alic')).toBeNull()
expect(detectTrigger('text\n/skill')).toBeNull()
expect(detectTrigger('multi word message /')).toBeNull()
})
it('still anchors at-mention triggers strictly at the token edge', () => {
expect(detectTrigger('@file:path with space')).toBeNull()
})

View file

@ -11,8 +11,12 @@ export interface TriggerState {
// user types args (`/personality alic` → arg completer suggests `alice`).
// Restricting the slash command name to `[a-zA-Z][\w-]*` avoids matching file
// paths like `src/foo/bar`.
//
// Slash commands only execute at the beginning of a message, so the `/`
// trigger is anchored strictly at position 0 — not after whitespace — to
// avoid opening the popover mid-message (e.g. `hello /`).
const AT_TRIGGER_RE = /(?:^|[\s])(@)([^\s@/]*)$/
const SLASH_TRIGGER_RE = /(?:^|[\s])(\/)((?:[a-zA-Z][\w-]*(?:\s+\S*)*)?)$/
const SLASH_TRIGGER_RE = /^(\/)((?:[a-zA-Z][\w-]*(?:\s+\S*)*)?)$/
/** Stable key for paste dedupe — `items` and `files` often mirror the same image as different objects. */
export function blobDedupeKey(blob: Blob): string {