fix(app): support nested slash command autocomplete (#38097)

This commit is contained in:
Daniel Polito 2026-07-21 12:08:23 -03:00 committed by GitHub
parent 21c4c93770
commit b513fafe83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -26,6 +26,19 @@ describe("prompt input v2 interaction machine", () => {
expect(closed.state.popover).toEqual({ type: "closed" })
})
test("completes nested slash command names", () => {
const open = transitionPromptInputV2(
createPromptInputV2InteractionState(),
{ type: "input.changed", value: "/review/" },
persisted(),
)
const item = { ...command, label: "/review/nested" }
const selected = transitionPromptInputV2(open.state, { type: "popover.select", item }, persisted("/review/"))
expect(open.state.popover).toEqual({ type: "command-inline", query: "review/" })
expect(selected.commands).toContainEqual({ type: "draft.setText", value: "/review/nested " })
})
test("opens context completion at the cursor", () => {
const value = "alpha @sr omega"
const input = persisted(value)

View file

@ -102,7 +102,7 @@ function inputChanged(
])
}
const command = value.match(/^\/([^\s/]*)$/)
const command = value.match(/^\/(\S*)$/)
if (command) {
const query = command[1] ?? ""
return changed({ ...state, popover: { type: "command-inline", query }, focus: "editor" }, [
@ -240,7 +240,7 @@ function populated(persisted: PromptInputV2PersistedState) {
}
function replaceTrigger(value: string, trigger: "@" | "/", replacement: string) {
const index = value.lastIndexOf(trigger)
const index = trigger === "/" ? value.indexOf(trigger) : value.lastIndexOf(trigger)
return index < 0 ? replacement : value.slice(0, index) + replacement
}