Add supported VBA for monaco

This commit is contained in:
Alexey Koshelev
2025-05-05 15:40:42 +03:00
parent 0af9ac3194
commit 121856a80a
4 changed files with 33 additions and 6 deletions

View File

@ -41,6 +41,7 @@ define([], function () {
Common.UI.BaseView.prototype.initialize.call(this, options);
this.parentEl = options.parentEl;
this.language = options.language || 'javascript';
this.parentEl && this.render(this.parentEl);
},
@ -59,7 +60,11 @@ define([], function () {
this.loadMask = new Common.UI.LoadMask({owner: this.parentEl});
this.loadMask.show();
this.iframe.src = '../../../vendor/monaco/MonacoEditor.html?editorType=' + (window.SSE ? 'cell' : window.PE ? 'slide' : 'word');
var src = '../../../vendor/monaco/MonacoEditor.html';
src += '?editorType=' + (window.SSE ? 'cell' : window.PE ? 'slide' : 'word');
src += '&language=' + this.language;
this.iframe.src = src;
var me = this;
this._eventfunc = function(msg) {

View File

@ -36,6 +36,7 @@
var params = getUrlParams();
window.editorType = params["editorType"]; // word/cell/slide
window.editorTheme = params["editorTheme"]; // dark/light
window.language = params["language"]; //javascript/vba
</script>
<script src="./MonacoEditorCode.js"></script>
</body>

View File

@ -34,7 +34,8 @@ var codeEditor = new window.MonacoEditor();
codeEditor.create("editor", window.editorTheme === "dark" ? "vs-dark" : "vs-light", "", {
minimap: {
enabled: false
}
},
language: window.language
}, function() {
_postMessage({
command: 'monacoEditorReady',
@ -42,10 +43,12 @@ codeEditor.create("editor", window.editorTheme === "dark" ? "vs-dark" : "vs-ligh
});
});
codeEditor.addLibrary({
url: "./libs/" + window.editorType + "/api.js",
name : "onlyoffice"
});
if(window.language == 'javascript') {
codeEditor.addLibrary({
url: "./libs/" + window.editorType + "/api.js",
name : "onlyoffice"
});
}
var _postMessage = function(msg) {
window.parent && window.JSON && window.parent.postMessage(window.JSON.stringify(msg), "*");

View File

@ -62,6 +62,7 @@
for (let i in this.options)
options[i] = this.options[i];
this._registerLanguage(options.language);
this.editor = monaco.editor.create(document.getElementById(this.parent), options);
this._loadLibraries();
this._loadEvents();
@ -119,6 +120,23 @@
monaco.languages.typescript.javascriptDefaults.addExtraLib(libraries[i].code, libraries[i].name);
}
};
MonacoEditor.prototype._registerLanguage = function(language) {
if(language == 'vba') {
monaco.languages.register({ id: 'vba' });
monaco.languages.setMonarchTokensProvider('vba', {
tokenizer: {
root: [
[/\b(?:Sub|End Sub|Function|End Function|If|Then|Else|End If|Dim|As|Set|New|For|Each|Next|Do|Loop|While|Wend|Select Case|Case|End Select|Exit|With|End With|Call|Private|Public|Const|GoTo|On Error)\b/, 'keyword'],
[/"([^"]*)"/, 'string'],
[/\b[A-Za-z_][A-Za-z0-9_]*\b/, 'identifier'],
[/\d+/, 'number'],
[/'.*$/, 'comment']
]
}
});
}
};
MonacoEditor.prototype.dispose = function() {
for (let i = 0; i < REGISTERED_EDITORS.length; i++) {