From a3a6b7728a76d6af8fb2dd9e971914aa3abe2ed9 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 11 Jan 2025 10:28:14 -0800 Subject: [PATCH] don't create new file when base name matches current file --- .../StepContainerPreToolbar.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 95361abb2..45faf550a 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -94,11 +94,21 @@ export default function StepContainerPreToolbar( return; } - const fileUri = await inferResolvedUriFromRelativePath( + let fileUri = await inferResolvedUriFromRelativePath( props.relativeFilepath, ideMessenger.ide, ); + // Sometimes the model will decide to only output the base name + // in which case we shouldn't create a new file if it matches the current file + const exists = await ideMessenger.ide.fileExists(fileUri); + if (!exists) { + const activeFile = await ideMessenger.ide.getCurrentFile(); + if (activeFile && activeFile.path.endsWith(props.relativeFilepath)) { + fileUri = activeFile.path; + } + } + ideMessenger.post("applyToFile", { streamId: streamIdRef.current, filepath: fileUri,