(item?: PromptOption)
| 840 | } |
| 841 | |
| 842 | const select = (item?: PromptOption) => { |
| 843 | const next = item ?? options()[menu.selected()] |
| 844 | if (!next || !area || area.isDestroyed) { |
| 845 | return |
| 846 | } |
| 847 | |
| 848 | if (next.kind === "slash") { |
| 849 | if (next.action === "editor") { |
| 850 | void openEditor({ |
| 851 | value: resolveEditorSlashValue(area.plainText), |
| 852 | }) |
| 853 | return |
| 854 | } |
| 855 | |
| 856 | if (next.action === "skill-menu") { |
| 857 | cancelAutocomplete() |
| 858 | input.onSkillMenu() |
| 859 | return |
| 860 | } |
| 861 | |
| 862 | const cursor = area.cursorOffset |
| 863 | const head = slashHead(area.plainText) |
| 864 | const local = !shell() && (next.name === "new" || next.name === "exit") |
| 865 | const separator = !shell() && !local && head && /\s/.test(area.plainText[head.end] ?? "") ? "" : " " |
| 866 | const text = `/${next.name}${separator}` |
| 867 | |
| 868 | area.cursorOffset = 0 |
| 869 | const start = area.logicalCursor |
| 870 | area.cursorOffset = |
| 871 | shell() || !head |
| 872 | ? cursor |
| 873 | : local |
| 874 | ? Bun.stringWidth(area.plainText) |
| 875 | : Bun.stringWidth(area.plainText.slice(0, head.end)) |
| 876 | const end = area.logicalCursor |
| 877 | |
| 878 | area.deleteRange(start.row, start.col, end.row, end.col) |
| 879 | area.insertText(text) |
| 880 | area.cursorOffset = Bun.stringWidth(text) |
| 881 | hide() |
| 882 | syncDraft() |
| 883 | if (!shell()) { |
| 884 | submitPrompt(clonePrompt(draft)) |
| 885 | return |
| 886 | } |
| 887 | |
| 888 | scheduleRows() |
| 889 | area.focus() |
| 890 | return |
| 891 | } |
| 892 | |
| 893 | const cursor = area.cursorOffset |
| 894 | const tail = displayCharAt(area.plainText, cursor) |
| 895 | const append = "@" + next.value + (tail === " " ? "" : " ") |
| 896 | area.cursorOffset = at() |
| 897 | const start = area.logicalCursor |
| 898 | area.cursorOffset = cursor |
| 899 | const end = area.logicalCursor |
no test coverage detected