mirror of
https://github.com/anomalyco/opencode.git
synced 2026-08-14 18:53:25 +00:00
fix(app): support nested slash command autocomplete (#38097)
This commit is contained in:
parent
21c4c93770
commit
b513fafe83
2 changed files with 15 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue