Skip to content

Commit

Permalink
fixed mark changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
VictoriaShyika committed Dec 11, 2023
1 parent e856617 commit f58281c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export default function WorkspaceTreeView() {
className="radius-s foreground-primary"
title="unsaved file"
style={{ width: "6px", height: "6px" }}
></div>
/>
)}
</span>
</>
Expand Down
5 changes: 4 additions & 1 deletion src/pages/main/processor/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ export const markChangedFolders = (
fileTree: TFileNodeTreeData,
file: TFileNode,
dispatch: Dispatch<AnyAction>,
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/main/processor/hooks/useNodeTreeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/pages/main/processor/hooks/useSaveCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ 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"]);
if (fileData.changed) {
try {
await saveFileContent(project, fileHandlers, currentFileUid, fileData);
} catch (err) {}

while (file) {
file.data.changed = false;
file = _ffTree[file.parentUid!];
}
}
removeRunningActions(["processor-save-currentFile"]);

Expand Down

0 comments on commit f58281c

Please sign in to comment.