Skip to content

Commit daa95b1

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 dc02f75 commit daa95b1

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
@@ -696,6 +696,7 @@ async function getLocalFilesystem(repoid: string): Promise<ProjectFilesystem> {
696696
alertError(`Could not get permission to access filesystem.`);
697697
return;
698698
}
699+
const lastWriteTime: { [path: string]: number } = {};
699700
return {
700701
getFileData: async (path) => {
701702
console.log('getFileData', path);
@@ -708,6 +709,7 @@ async function getLocalFilesystem(repoid: string): Promise<ProjectFilesystem> {
708709
return contents;
709710
},
710711
setFileData: async (path, data) => {
712+
lastWriteTime[path] = Date.now();
711713
const fileHandle = await dirHandle.getFileHandle(path, { create: true });
712714
const writable = await fileHandle.createWritable();
713715
await writable.write(data);
@@ -724,7 +726,12 @@ async function getLocalFilesystem(repoid: string): Promise<ProjectFilesystem> {
724726
// TODO Handle different types of changes intelligently.
725727
// https://developer.mozilla.org/docs/Web/API/FileSystemChangeRecord#type
726728
if (record.changedHandle) {
727-
callback(record.changedHandle.name);
729+
const path = record.changedHandle.name;
730+
// Ignore filesystem notifications that are likely from our own recent writes,
731+
// so that onFileChanged in ui.ts doesn't call assets editor's refresh(true).
732+
// TODO: Consider better options than a time based threshold.
733+
if (Date.now() - (lastWriteTime[path] || 0) < 2000) continue;
734+
callback(path);
728735
}
729736
}
730737
});

0 commit comments

Comments
 (0)