diff --git a/core/commands/slash/edit.ts b/core/commands/slash/edit.ts index 80b773d88..f94172499 100644 --- a/core/commands/slash/edit.ts +++ b/core/commands/slash/edit.ts @@ -230,13 +230,18 @@ const EditSlashCommand: SlashCommand = { } // Strip unecessary parts of the input (the fact that you have to do this is suboptimal, should be refactored away) - input = input.replace( + let content = history[history.length - 1].content; + if (typeof content !== "string") { + content.forEach((part) => { + if (part.text && part.text.startsWith("/edit")) { + part.text = part.text.replace("/edit", "").trimStart(); + } + }) + } + let userInput = stripImages(content).replace( `\`\`\`${contextItemToEdit.name}\n${contextItemToEdit.content}\n\`\`\`\n`, "" ); - if (input.startsWith("/edit")) { - input = input.replace("/edit", "").trimStart(); - } const rif: RangeInFileWithContents = contextItemToRangeInFileWithContents(contextItemToEdit); @@ -248,14 +253,14 @@ const EditSlashCommand: SlashCommand = { rif, fullFileContents, llm, - input, + userInput, params?.tokenLimit ); const [dedentedContents, commonWhitespace] = dedentAndGetCommonWhitespace(contents); contents = dedentedContents; - let prompt = compilePrompt(filePrefix, contents, fileSuffix, input); + let prompt = compilePrompt(filePrefix, contents, fileSuffix, userInput); let fullFileContentsLines = fullFileContents.split("\n"); let fullPrefixLines = fullFileContentsLines.slice( 0, @@ -447,7 +452,7 @@ const EditSlashCommand: SlashCommand = { messages.slice(0, messages.length - 1), { codeToEdit: rif.contents, - userInput: input, + userInput, filePrefix: filePrefix, fileSuffix: fileSuffix, systemMessage: llm.systemMessage || "", diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index dee35d1aa..0460c719e 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -34,6 +34,8 @@ async function resolveEditorContent( for (const p of editorState?.content) { if (p.type === "paragraph") { const [text, ctxItems, foundSlashCommand] = resolveParagraph(p); + + // Only take the first slash command if (foundSlashCommand && typeof slashCommand === "undefined") { slashCommand = foundSlashCommand; } @@ -92,8 +94,9 @@ async function resolveEditorContent( if (item.itemType === "file") { // This is a quick way to resolve @file references const basename = getBasename(item.id); - const content = await ide.readFile(item.id); - contextItemsText += `\`\`\`title="${basename}"\n${content}\n\`\`\`\n`; + const rawContent = await ide.readFile(item.id); + const content = `\`\`\`title="${basename}"\n${rawContent}\n\`\`\`\n`; + contextItemsText += content contextItems.push({ name: basename, description: item.id,