Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit 0aa8af4

Browse files
authored
Merge pull request #453 from reorproject/fix-renaming-bug
fix rename bug
2 parents 05ae423 + 923c417 commit 0aa8af4

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/contexts/FileContext.tsx

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,14 @@ export const FileProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
205205
}
206206
}, [spellCheckEnabled, editor])
207207

208-
const [debouncedEditor] = useDebounce(editor?.state.doc.content, 4000)
208+
const [debouncedEditor] = useDebounce(editor?.state.doc.content, 3000)
209209

210210
useEffect(() => {
211211
if (debouncedEditor && !currentlyChangingFilePath) {
212212
writeEditorContentToDisk(editor, currentlyOpenFilePath)
213+
if (editor && currentlyOpenFilePath) {
214+
handleNewFileRenaming(editor, currentlyOpenFilePath)
215+
}
213216
}
214217
}, [debouncedEditor, currentlyOpenFilePath, editor, currentlyChangingFilePath])
215218

@@ -227,26 +230,29 @@ export const FileProvider: React.FC<{ children: ReactNode }> = ({ children }) =>
227230
})
228231
setNeedToWriteEditorContentToDisk(false)
229232
}
233+
}
234+
}
230235

231-
const fileInfo = vaultFilesFlattened.find((f) => f.path === filePath)
232-
if (
233-
fileInfo &&
234-
fileInfo.name.startsWith('Untitled') &&
235-
new Date().getTime() - fileInfo.dateCreated.getTime() < 60000
236-
) {
237-
const editorText = editor?.getText()
238-
if (editorText) {
239-
const newProposedFileName = generateFileNameFromFileContent(editorText)
240-
if (newProposedFileName) {
241-
const directoryToMakeFileIn = await window.path.dirname(filePath)
242-
const filesInDirectory = await getFilesInDirectory(directoryToMakeFileIn, vaultFilesFlattened)
243-
const fileName = getNextAvailableFileNameGivenBaseName(
244-
filesInDirectory.map((file) => file.name),
245-
newProposedFileName,
246-
)
247-
const newFilePath = await window.path.join(directoryToMakeFileIn, fileName)
248-
await renameFile(filePath, newFilePath)
249-
}
236+
const handleNewFileRenaming = async (_editor: Editor, filePath: string) => {
237+
const fileInfo = vaultFilesFlattened.find((f) => f.path === filePath)
238+
if (
239+
fileInfo &&
240+
fileInfo.name.startsWith('Untitled') &&
241+
new Date().getTime() - fileInfo.dateCreated.getTime() < 60000
242+
) {
243+
const editorText = _editor.getText()
244+
if (editorText) {
245+
const newProposedFileName = generateFileNameFromFileContent(editorText)
246+
if (newProposedFileName) {
247+
const directoryToMakeFileIn = await window.path.dirname(filePath)
248+
const filesInDirectory = await getFilesInDirectory(directoryToMakeFileIn, vaultFilesFlattened)
249+
const fileName = getNextAvailableFileNameGivenBaseName(
250+
filesInDirectory.map((file) => file.name),
251+
newProposedFileName,
252+
)
253+
const newFilePath = await window.path.join(directoryToMakeFileIn, fileName)
254+
await renameFile(filePath, newFilePath)
255+
// setCurrentlyOpenFilePath(newFilePath)
250256
}
251257
}
252258
}

src/lib/llm/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { createAnthropic } from '@ai-sdk/anthropic'
44
import { LanguageModel } from 'ai'
55

66
const resolveLLMClient = async (llmName: string): Promise<LanguageModel> => {
7+
if (!llmName || llmName === '') {
8+
throw new Error('No LLM has been configured. Please setup an LLM in settings.')
9+
}
710
const llmConfigs = await window.llm.getLLMConfigs()
811
const apiConfigs = await window.llm.getLLMAPIConfigs()
912

0 commit comments

Comments
 (0)