Skip to content

Commit 76d9bd0

Browse files
authored
feat(code): remove auto-submit from slash commands, fix search (#1237)
## problem 1. when typing to search for a command/skill, the scrolling/filtering does not work 2. commands are not available in the new task view 3. commands always nuke and auto-submit your prompt 4. duplicate skills show up in the list (e.g. one `(project)`and one `(repo-skills-xyz)` , they are keyed on `name`, so multiple skills end up getting highlighted at the same time when searching/filtering and breaking things ## changes 1. fixes scroll/filter when typing to search 2. adds commands to the new task view 3. changes to _not_ auto-submit prompts on command selection 4. deduplicates commands/skills by name 1. **no, this is not a very good solution, but it needs more thinking on how we actually want to handle duplicate commands/skills or their names**
1 parent d2782bc commit 76d9bd0

6 files changed

Lines changed: 10 additions & 42 deletions

File tree

apps/code/src/renderer/features/message-editor/suggestions/getSuggestions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export function getCommandSuggestions(
6666
query: string,
6767
): CommandSuggestionItem[] {
6868
const taskId = useDraftStore.getState().contexts[sessionId]?.taskId;
69-
const commands = [...CODE_COMMANDS, ...getAvailableCommandsForTask(taskId)];
69+
const merged = [...CODE_COMMANDS, ...getAvailableCommandsForTask(taskId)];
70+
const commands = [...new Map(merged.map((cmd) => [cmd.name, cmd])).values()];
7071
const filtered = searchCommands(commands, query);
7172

7273
return filtered.map((cmd) => ({

apps/code/src/renderer/features/message-editor/tiptap/CommandMention.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { SuggestionList, type SuggestionListRef } from "./SuggestionList";
99

1010
function createSuggestion(
1111
sessionId: string,
12-
onSubmit?: (text: string) => void,
13-
onClearDraft?: () => void,
1412
): Partial<SuggestionOptions<SuggestionItem>> {
1513
return {
1614
char: "/",
@@ -85,15 +83,7 @@ function createSuggestion(
8583
command: ({ editor, range, props }) => {
8684
const item = props as CommandSuggestionItem;
8785

88-
// Commands without input hints execute immediately
89-
if (!item.command.input?.hint) {
90-
editor.commands.clearContent();
91-
onClearDraft?.();
92-
onSubmit?.(`/${item.command.name}`);
93-
return;
94-
}
95-
96-
// Commands with input insert a chip
86+
// Insert command as a chip, let user add context and submit when ready
9787
editor
9888
.chain()
9989
.focus()
@@ -116,12 +106,10 @@ function createSuggestion(
116106

117107
export interface CommandMentionOptions {
118108
sessionId: string;
119-
onSubmit?: (text: string) => void;
120-
onClearDraft?: () => void;
121109
}
122110

123111
export function createCommandMention(options: CommandMentionOptions) {
124-
const { sessionId, onSubmit, onClearDraft } = options;
112+
const { sessionId } = options;
125113

126114
return Mention.extend<CommandMentionOptions>({
127115
name: "commandMention",
@@ -130,9 +118,7 @@ export function createCommandMention(options: CommandMentionOptions) {
130118
return {
131119
...this.parent?.(),
132120
sessionId,
133-
onSubmit,
134-
onClearDraft,
135-
suggestion: createSuggestion(sessionId, onSubmit, onClearDraft),
121+
suggestion: createSuggestion(sessionId),
136122
};
137123
},
138124
});

apps/code/src/renderer/features/message-editor/tiptap/SuggestionList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export const SuggestionList = forwardRef<
4141
setHasMouseMoved(false);
4242
}
4343

44+
// biome-ignore lint/correctness/useExhaustiveDependencies: re-scroll when items change
4445
useEffect(() => {
4546
itemRefs.current[selectedIndex]?.scrollIntoView({ block: "nearest" });
46-
}, [selectedIndex]);
47+
}, [selectedIndex, items]);
4748

4849
useImperativeHandle(ref, () => ({
4950
onKeyDown: ({ event }) => {

apps/code/src/renderer/features/message-editor/tiptap/extensions.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export interface EditorExtensionsOptions {
99
placeholder?: string;
1010
fileMentions?: boolean;
1111
commands?: boolean;
12-
onCommandSubmit?: (text: string) => void;
13-
onClearDraft?: () => void;
1412
}
1513

1614
export function getEditorExtensions(options: EditorExtensionsOptions) {
@@ -19,8 +17,6 @@ export function getEditorExtensions(options: EditorExtensionsOptions) {
1917
placeholder = "",
2018
fileMentions = true,
2119
commands = true,
22-
onCommandSubmit,
23-
onClearDraft,
2420
} = options;
2521

2622
const extensions = [
@@ -46,13 +42,7 @@ export function getEditorExtensions(options: EditorExtensionsOptions) {
4642
}
4743

4844
if (commands) {
49-
extensions.push(
50-
createCommandMention({
51-
sessionId,
52-
onSubmit: onCommandSubmit,
53-
onClearDraft,
54-
}),
55-
);
45+
extensions.push(createCommandMention({ sessionId }));
5646
}
5747

5848
return extensions;

apps/code/src/renderer/features/message-editor/tiptap/useTiptapEditor.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,13 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
9595
const [attachments, setAttachments] = useState<FileAttachment[]>([]);
9696
const attachmentsRef = useRef<FileAttachment[]>([]);
9797

98-
const handleCommandSubmit = useCallback((text: string) => {
99-
callbackRefs.current.onSubmit?.(text);
100-
}, []);
101-
102-
const handleClearDraft = useCallback(() => {
103-
draftRef.current?.clearDraft();
104-
}, []);
105-
10698
const editor = useEditor(
10799
{
108100
extensions: getEditorExtensions({
109101
sessionId,
110102
placeholder,
111103
fileMentions,
112104
commands,
113-
onCommandSubmit: handleCommandSubmit,
114-
onClearDraft: handleClearDraft,
115105
}),
116106
editable: !disabled,
117107
autofocus: autoFocus ? "end" : false,

apps/code/src/renderer/features/task-detail/components/TaskInputEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export const TaskInputEditor = forwardRef<
7979
submitDisabled: !isOnline,
8080
isLoading: isCreatingTask,
8181
autoFocus,
82-
context: { repoPath },
83-
capabilities: { commands: false, bashMode: false },
82+
context: { repoPath, taskId: previewTaskId },
83+
capabilities: { commands: true, bashMode: false },
8484
clearOnSubmit: false,
8585
onSubmit: (text) => {
8686
if (text && canSubmit) {

0 commit comments

Comments
 (0)