Skip to content

Commit 73dc16f

Browse files
committed
Fix asset editor local dir interaction
Ignore filesystem file change notifications that are likely from our making edits in the asset editor, so that the editor isn't refreshed and changing out from under us.
1 parent ac38b62 commit 73dc16f

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/ide/ui.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ async function getLocalFilesystem(repoid: string): Promise<ProjectFilesystem> {
697697
alertError(`Could not get permission to access filesystem.`);
698698
return;
699699
}
700+
const lastWriteTime: { [path: string]: number } = {};
700701
return {
701702
getFileData: async (path) => {
702703
console.log('getFileData', path);
@@ -709,6 +710,7 @@ async function getLocalFilesystem(repoid: string): Promise<ProjectFilesystem> {
709710
return contents;
710711
},
711712
setFileData: async (path, data) => {
713+
lastWriteTime[path] = Date.now();
712714
const fileHandle = await dirHandle.getFileHandle(path, { create: true });
713715
const writable = await fileHandle.createWritable();
714716
await writable.write(data);
@@ -725,7 +727,12 @@ async function getLocalFilesystem(repoid: string): Promise<ProjectFilesystem> {
725727
// TODO Handle different types of changes intelligently.
726728
// https://developer.mozilla.org/docs/Web/API/FileSystemChangeRecord#type
727729
if (record.changedHandle) {
728-
callback(record.changedHandle.name);
730+
const path = record.changedHandle.name;
731+
// Ignore filesystem notifications that are likely from our own recent writes,
732+
// so that onFileChanged in ui.ts doesn't call assets editor's refresh(true).
733+
// TODO: Consider better options than a time based threshold.
734+
if (Date.now() - (lastWriteTime[path] || 0) < 2000) continue;
735+
callback(path);
729736
}
730737
}
731738
});

0 commit comments

Comments
 (0)