fx-compat: Style Editor: Validate inline (#2745)

This commit is contained in:
Abe Jellinek 2022-11-12 05:31:29 -05:00 committed by GitHub
parent e789872efe
commit 318ec4074e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -147,6 +147,10 @@ var Zotero_CSL_Editor = new function() {
this.onStyleModified = function () { this.onStyleModified = function () {
let xml = editor.getValue(); let xml = editor.getValue();
Zotero.Styles.validate(xml).then(
() => this.updateMarkers(''),
rawErrors => this.updateMarkers(rawErrors)
);
let cslList = document.getElementById('zotero-csl-list'); let cslList = document.getElementById('zotero-csl-list');
let savedStyle = Zotero.Styles.get(cslList.value); let savedStyle = Zotero.Styles.get(cslList.value);
if (!savedStyle || xml !== savedStyle?.getXML()) { if (!savedStyle || xml !== savedStyle?.getXML()) {
@ -238,18 +242,26 @@ var Zotero_CSL_Editor = new function() {
} }
styleEngine.free(); styleEngine.free();
} }
this.updateMarkers = function (rawErrors) {
// From http://kb.mozillazine.org/Inserting_text_at_cursor let model = editor.getModel();
function _insertText(text) { let errors = rawErrors ? rawErrors.split('\n') : [];
var command = "cmd_insertText"; let markers = errors.map((error) => {
var controller = document.commandDispatcher.getControllerForCommand(command); let matches = error.match(/^[^:]*:(?<line>[^:]*):(?<column>[^:]*): error: (?<message>.+)/);
if (controller && controller.isCommandEnabled(command)) { if (!matches) return null;
controller = controller.QueryInterface(Components.interfaces.nsICommandController); let { line, message } = matches.groups;
var params = Components.classes["@mozilla.org/embedcomp/command-params;1"]; line = parseInt(line);
params = params.createInstance(Components.interfaces.nsICommandParams); return {
params.setStringValue("state_data", "\t"); startLineNumber: line,
controller.doCommandWithParams(command, params); endLineNumber: line,
} // The error message doesn't give us an end column, so using its
} // start column looks weird. Just highlight the whole line.
startColumn: model.getLineFirstNonWhitespaceColumn(line),
endColumn: model.getLineMaxColumn(line),
message,
severity: 8
};
}).filter(Boolean);
monaco.editor.setModelMarkers(model, 'csl-validator', markers);
};
}(); }();