diff --git a/src/ide/views/asseteditor.ts b/src/ide/views/asseteditor.ts index 2c94c83d..1e76c2e6 100644 --- a/src/ide/views/asseteditor.ts +++ b/src/ide/views/asseteditor.ts @@ -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) { diff --git a/src/ide/views/baseviews.ts b/src/ide/views/baseviews.ts index 27e84264..13f2fa79 100644 --- a/src/ide/views/baseviews.ts +++ b/src/ide/views/baseviews.ts @@ -20,6 +20,7 @@ export interface ProjectView { recreateOnResize?: boolean; undoStep?(): void; redoStep?(): void; + flushChanges?(): void; replaceTextRange?(from: number, to: number, text: string): void; }; diff --git a/src/ide/views/editors.ts b/src/ide/views/editors.ts index cecd5394..41fcc7ab 100644 --- a/src/ide/views/editors.ts +++ b/src/ide/views/editors.ts @@ -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; diff --git a/src/ide/windows.ts b/src/ide/windows.ts index 07a80037..cffdc140 100644 --- a/src/ide/windows.ts +++ b/src/ide/windows.ts @@ -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];