Created
September 6, 2022 16:44
-
-
Save mturoci/5ff27b99ea6841a333b78cb54d1abcbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const baseUrl = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs' | |
// UNIMPORTANT: RequireJS paths config for monaco editor. | |
require.config({ | |
paths: { | |
'vs': baseUrl, | |
'vs/language': `${baseUrl}/language`, | |
} | |
}) | |
// UNIMPORTANT: Web worker registration for monaco editor. | |
window.MonacoEnvironment = { | |
getWorkerUrl: function (workerId, label) { | |
return `data:text/javascript;charset=utf-8,${encodeURIComponent(` | |
importScripts('${baseUrl}/base/worker/workerMain.js');` | |
)}` | |
} | |
} | |
// Load the editor javascript. | |
require(['vs/editor/editor.main'], async () => { | |
// Render the editor into our existing div with ID "editor". | |
const editor = monaco.editor.create(document.getElementById('editor'), { | |
language: 'python', | |
}) | |
// Use cmd (mac) or ctr + S to save content. | |
editor.addAction({ | |
id: 'save-content', | |
label: 'Save', | |
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS], | |
// Emit q.events.editor.save event on CMD+S. | |
run: editor => window.wave.emit('editor', 'save', editor.getValue()) | |
}) | |
// When the editor text changes, emit q.events.editor.change event | |
// to mark dirty state. | |
editor.onDidChangeModelContent(() => window.wave.emit('editor', 'change', true)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment