mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2026-10-25 00:02:16 +00:00
Asset editor flushes pending writes
Avoid asset editor seeing stale data or project file writes being lost when a delayed editor read/write competes with a synchronous asset editor read/write
This commit is contained in:
1 parent
6ce80f9154
commit
ad5da2d810
4 files changed
+21
-1
No files matched your search
@@ -477,7 +477,9 @@ export class AssetEditorView implements ProjectView, pixed.EditorContext {
|
||||
setVisible?(showing: boolean): void {
|
||||
// TODO: make into toolbar?
|
||||
if (showing) {
|
||||
// limit undo/redo to since opening this editor
|
||||
// ensure asset editor is safe to perform synchronous reads/writes
|
||||
projectWindows.flushAllWindows();
|
||||
// limit undo/redo to since opening this asset editor
|
||||
projectWindows.undofiles = [];
|
||||
projectWindows.redofiles = [];
|
||||
if (Mousetrap.bind) {
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface ProjectView {
|
||||
recreateOnResize?: boolean;
|
||||
undoStep?(): void;
|
||||
redoStep?(): void;
|
||||
flushChanges?(): void;
|
||||
replaceTextRange?(from: number, to: number, text: string): void;
|
||||
};
|
||||
|
||||
|
||||
@@ -282,6 +282,14 @@ export class SourceEditor implements ProjectView {
|
||||
}, this.refreshDelayMsec);
|
||||
}
|
||||
|
||||
flushChanges() {
|
||||
if (this.updateTimer) {
|
||||
clearTimeout(this.updateTimer);
|
||||
this.updateTimer = null;
|
||||
current_project.updateFile(this.path, this.editor.state.doc.toString());
|
||||
}
|
||||
}
|
||||
|
||||
inspectUnderCursor(update: ViewUpdate) {
|
||||
// TODO: handle multi-select
|
||||
const range = update.state.selection.main;
|
||||
|
||||
@@ -208,6 +208,15 @@ export class ProjectWindows {
|
||||
bootbox.alert(msg, () => { this.alerting = false; });
|
||||
}
|
||||
|
||||
flushAllWindows() {
|
||||
for (var fileid in this.id2window) {
|
||||
var wnd = this.id2window[fileid];
|
||||
if (wnd && wnd.flushChanges) {
|
||||
wnd.flushChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateAllOpenWindows(store) {
|
||||
for (var fileid in this.id2window) {
|
||||
var wnd = this.id2window[fileid];
|
||||
|
||||
Reference in new issue
Block a user