fix(ui): per-field sub-schema for escape-hatch Monaco editors + dispose guard (#261)
This commit is contained in:
@@ -330,12 +330,16 @@
|
||||
// A json editor with a schema needs an explicitly-URI'd model so the
|
||||
// schema's fileMatch can target exactly this editor.
|
||||
let model = null;
|
||||
let hasSchema = false;
|
||||
if (isJson) {
|
||||
const uri = modelUriFor(id);
|
||||
model = monaco.editor.getModel(uri);
|
||||
if (model) { model.setValue(options.value || ""); }
|
||||
else { model = monaco.editor.createModel(options.value || "", "json", uri); }
|
||||
if (options.jsonSchema) { applyJsonSchema(id, options.jsonSchema); }
|
||||
if (options.jsonSchema && options.jsonSchema.trim().length > 0) {
|
||||
applyJsonSchema(id, options.jsonSchema);
|
||||
hasSchema = true;
|
||||
}
|
||||
}
|
||||
|
||||
const editor = monaco.editor.create(host, {
|
||||
@@ -372,7 +376,7 @@
|
||||
dotNetRef.invokeMethodAsync("OnValueChanged", value).catch(function () {});
|
||||
if (options.language === "csharp") scheduleDiagnostics();
|
||||
});
|
||||
editors[id] = { editor: editor, dotNetRef: dotNetRef, isJson: isJson };
|
||||
editors[id] = { editor: editor, dotNetRef: dotNetRef, isJson: isJson, hasSchema: hasSchema };
|
||||
|
||||
// Run an initial diagnostic pass so existing scripts show their markers.
|
||||
if (language === "csharp") scheduleDiagnostics();
|
||||
@@ -381,6 +385,9 @@
|
||||
function setJsonSchema(id, schemaJson) {
|
||||
const entry = editors[id];
|
||||
if (!entry || !entry.isJson) return;
|
||||
// Track whether this editor currently owns a schema entry in jsonDefaults
|
||||
// so dispose can skip the teardown interop when there is nothing to drop.
|
||||
entry.hasSchema = !!(schemaJson && schemaJson.trim().length > 0);
|
||||
applyJsonSchema(id, schemaJson);
|
||||
}
|
||||
|
||||
@@ -436,7 +443,9 @@
|
||||
if (!entry) return;
|
||||
// Drop this editor's json schema entry and its explicitly-URI'd model so
|
||||
// a disposed json editor leaves nothing behind in the global defaults.
|
||||
if (entry.isJson) {
|
||||
// Skip the schema teardown for a json editor that never had a schema —
|
||||
// there is no entry to remove, so the applyJsonSchema interop is spurious.
|
||||
if (entry.isJson && entry.hasSchema) {
|
||||
try { applyJsonSchema(id, null); } catch (e) {}
|
||||
}
|
||||
try { entry.editor.dispose(); } catch (e) {}
|
||||
|
||||
Reference in New Issue
Block a user