monaco-editor
monaco-editor copied to clipboard
[Bug] Editor is uninteractive
Reproducible in vscode.dev or in VS Code Desktop?
- [X] Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- [x] Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Not reproducible in the monaco editor playground, but here is a codeflow link. https://stackblitz.com/~/github.com/caleb1248/monaco-editor-test
Monaco Editor Playground Code
Not reproducible in the monaco editor playground.
Reproduction Steps
main.ts
import * as monaco from 'monaco-editor';
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
self.MonacoEnvironment = {
getWorker: function (_moduleId: any, label: string) {
if (label === 'json') {
return new jsonWorker();
}
if (label === 'css' || label === 'scss' || label === 'less') {
return new cssWorker();
}
if (label === 'html' || label === 'handlebars' || label === 'razor') {
return new htmlWorker();
}
if (label === 'typescript' || label === 'javascript') {
return new tsWorker();
}
return new editorWorker();
}
};
const editorDiv = document.body.appendChild(document.createElement('div'));
const model = monaco.editor.createModel(
'console.log("hello world")',
undefined,
monaco.Uri.parse('file://code/index.ts')
);
const editor = monaco.editor.create(editorDiv, {
language: 'typescript',
theme: 'vs-dark',
automaticLayout: true
});
editor.setModel(model);
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
html,
body,
div {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<title>Vite + TS</title>
</head>
<body>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
I am using vite + typescript.
Actual (Problematic) Behavior
The editor is uninteractive - the cursor stays as the normal cursor, clicking has no effect, and I can't type anything.
Expected Behavior
I would expect the editor to be interactive.
Additional Context
There are no messages or errors in the console.
The problem was that the div style applied to all divs, which was interfering with another monaco-editor placed div. I changed it to affect only the editor div and it fixed.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
html,
body,
div#editor {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<title>Vite + TS</title>
</head>
<body>
<script type="module" src="/src/main.ts"></script>
</body>
</html>