From f58281ca260240154f883661074b757799ce1869 Mon Sep 17 00:00:00 2001 From: VictoriaShyika Date: Mon, 11 Dec 2023 16:12:24 +0200 Subject: [PATCH] fixed mark changed files --- .../actionsPanel/workspaceTreeView/WorkspaceTreeView.tsx | 2 +- src/pages/main/processor/helpers.ts | 5 ++++- src/pages/main/processor/hooks/useNodeTreeEvent.ts | 4 ++-- src/pages/main/processor/hooks/useSaveCommand.ts | 7 ++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/main/actionsPanel/workspaceTreeView/WorkspaceTreeView.tsx b/src/components/main/actionsPanel/workspaceTreeView/WorkspaceTreeView.tsx index 5c18bc4f..6310f6b5 100644 --- a/src/components/main/actionsPanel/workspaceTreeView/WorkspaceTreeView.tsx +++ b/src/components/main/actionsPanel/workspaceTreeView/WorkspaceTreeView.tsx @@ -615,7 +615,7 @@ export default function WorkspaceTreeView() { className="radius-s foreground-primary" title="unsaved file" style={{ width: "6px", height: "6px" }} - > + /> )} diff --git a/src/pages/main/processor/helpers.ts b/src/pages/main/processor/helpers.ts index f6aea0d8..3ed8555d 100644 --- a/src/pages/main/processor/helpers.ts +++ b/src/pages/main/processor/helpers.ts @@ -80,11 +80,14 @@ export const markChangedFolders = ( fileTree: TFileNodeTreeData, file: TFileNode, dispatch: Dispatch, + value: boolean, ) => { const parentFiles: TFileNode[] = []; while (file.parentUid) { const parentFile = structuredClone(fileTree[file.parentUid]); - parentFile.data.changed = true; + + // Depending on value folders are marked or unmarked + parentFile.data.changed = value; parentFiles.push(parentFile); file = parentFile; } diff --git a/src/pages/main/processor/hooks/useNodeTreeEvent.ts b/src/pages/main/processor/hooks/useNodeTreeEvent.ts index 735f35f7..78bf2ba6 100644 --- a/src/pages/main/processor/hooks/useNodeTreeEvent.ts +++ b/src/pages/main/processor/hooks/useNodeTreeEvent.ts @@ -96,8 +96,8 @@ export const useNodeTreeEvent = () => { fileData.content = currentFileContent; fileData.contentInApp = contentInApp; fileData.changed = fileData.content !== fileData.orgContent; - if (fileData.changed && file.parentUid) { - markChangedFolders(fileTree, file, dispatch); + if (file.parentUid) { + markChangedFolders(fileTree, file, dispatch, fileData.changed); } // when "Save" while text-editing, we need to call "Save" command after file-content updated. diff --git a/src/pages/main/processor/hooks/useSaveCommand.ts b/src/pages/main/processor/hooks/useSaveCommand.ts index 85709b51..05221787 100644 --- a/src/pages/main/processor/hooks/useSaveCommand.ts +++ b/src/pages/main/processor/hooks/useSaveCommand.ts @@ -35,7 +35,7 @@ export const useSaveCommand = () => { if (!fileTree[RootNodeUid]) return; const _ffTree = structuredClone(fileTree); - const file = _ffTree[currentFileUid]; + let file = _ffTree[currentFileUid]; const fileData = file.data; addRunningActions(["processor-save-currentFile"]); @@ -43,6 +43,11 @@ export const useSaveCommand = () => { try { await saveFileContent(project, fileHandlers, currentFileUid, fileData); } catch (err) {} + + while (file) { + file.data.changed = false; + file = _ffTree[file.parentUid!]; + } } removeRunningActions(["processor-save-currentFile"]);