From 1018ad87b8d7945ffd9f1a953d96ff94b823562b Mon Sep 17 00:00:00 2001 From: Pleasure1234 <3196812536@qq.com> Date: Fri, 31 Oct 2025 14:17:06 +0000 Subject: [PATCH] fix: cancel debounced save on file path update (#11069) Adds cancellation of the debounced save when the active file path is updated after moving a file or folder. This prevents saving to the old path and ensures lastFilePathRef is updated accordingly. --- src/renderer/src/pages/notes/NotesPage.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/pages/notes/NotesPage.tsx b/src/renderer/src/pages/notes/NotesPage.tsx index bbd57b9da1..fb7df83bfd 100644 --- a/src/renderer/src/pages/notes/NotesPage.tsx +++ b/src/renderer/src/pages/notes/NotesPage.tsx @@ -716,10 +716,17 @@ const NotesPage: FC = () => { const normalizedActivePath = activeFilePath ? normalizePathValue(activeFilePath) : undefined if (normalizedActivePath) { if (normalizedActivePath === sourceNode.externalPath) { + // Cancel debounced save to prevent saving to old path + debouncedSaveRef.current?.cancel() + lastFilePathRef.current = destinationPath dispatch(setActiveFilePath(destinationPath)) } else if (sourceNode.type === 'folder' && normalizedActivePath.startsWith(`${sourceNode.externalPath}/`)) { const suffix = normalizedActivePath.slice(sourceNode.externalPath.length) - dispatch(setActiveFilePath(`${destinationPath}${suffix}`)) + const newActivePath = `${destinationPath}${suffix}` + // Cancel debounced save to prevent saving to old path + debouncedSaveRef.current?.cancel() + lastFilePathRef.current = newActivePath + dispatch(setActiveFilePath(newActivePath)) } }