ignore disk events for files we save

This commit is contained in:
Matt Parker
2025-10-10 00:41:37 +10:00
parent 8791a23c19
commit f65ad7f18c
4 changed files with 24 additions and 8 deletions

View File

@@ -57,7 +57,7 @@ public class IdeFileManager
if (file.IsDirty.Value is false) return;
var text = await GetFileTextAsync(file);
await File.WriteAllTextAsync(file.Path, text);
await WriteAllText(file, text);
file.IsDirty.Value = false;
}
@@ -70,10 +70,23 @@ public class IdeFileManager
}
else
{
await File.WriteAllTextAsync(file.Path, newText);
await WriteAllText(file, newText);
}
}
private static async Task WriteAllText(SharpIdeFile file, string text)
{
file.SuppressDiskChangeEvents.Value = true;
await File.WriteAllTextAsync(file.Path, text);
Console.WriteLine($"Saved file {file.Path}");
_ = Task.Delay(300).ContinueWith(_ =>
{
Console.WriteLine($"Re-enabling disk change events for {file.Path}");
file.SuppressDiskChangeEvents.Value = false;
Console.WriteLine($"Value is now {file.SuppressDiskChangeEvents.Value}");
}, CancellationToken.None, TaskContinuationOptions.RunContinuationsAsynchronously, TaskScheduler.Default);
}
public async Task SaveAllOpenFilesAsync()
{
foreach (var file in _openFiles.Keys.ToList())