Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions webapp/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,31 @@ export class EditorPackage {
let cfgFile = this.files[pxt.CONFIG_NAME]
if (cfgFile) {
try {
let cfg = <pxt.PackageConfig>JSON.parse(cfgFile.content)
let currentContent = cfgFile.content;
const monacoEditor = typeof window !== "undefined" && (window as any).monaco?.editor;
const pxtJsonModel = monacoEditor?.getModels?.()?.find((m: any) => m.uri?.toString() === "pkg:" + pxt.CONFIG_NAME);
if (pxtJsonModel) {
try {
JSON.parse(pxtJsonModel.getValue());
currentContent = pxtJsonModel.getValue();
} catch {
// Monaco content is not valid JSON yet, fallback to cfgFile.content
}
}

let cfg = <pxt.PackageConfig>JSON.parse(currentContent);
update(cfg);
return cfgFile.setContentAsync(pxt.Package.stringifyConfig(cfg))
.then(() => this.ksPkg.loadConfig())
} catch (e) { }
const newContent = pxt.Package.stringifyConfig(cfg);

if (pxtJsonModel && pxtJsonModel.getValue() !== newContent) {
pxtJsonModel.setValue(newContent);
}

return cfgFile.setContentAsync(newContent, true)
.then(() => this.ksPkg.loadConfig());
} catch (e) {
// Pass
}
}

return null;
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/pxtjson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ export class Editor extends srceditor.Editor {
this.config = JSON.parse(file.content)
this.setDiagnostics(file, this.snapshotState())
this.changeMade = false;
file.setForceChangeCallback((from, to) => {
if (from != to) {
this.loadFileAsync(file).then(() => this.parent.forceUpdate());
}
});
return Promise.resolve();
}

Expand Down