mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
language logic
This commit is contained in:
parent
1afb39b155
commit
8a17c9246b
1 changed files with 14 additions and 23 deletions
|
|
@ -349,38 +349,29 @@ export const VoidCodeEditor = ({ initValue, language }: { initValue: string, lan
|
|||
}
|
||||
|
||||
onCreateInstance={useCallback((editor: CodeEditorWidget) => {
|
||||
const model = modelService.createModel(initValue, null)
|
||||
const model = modelService.createModel(
|
||||
initValue,
|
||||
language ? {
|
||||
languageId: language,
|
||||
onDidChange: () => ({
|
||||
dispose: () => { }
|
||||
})
|
||||
} : null
|
||||
);
|
||||
editor.setModel(model);
|
||||
|
||||
if (language) {
|
||||
model.setLanguage(language)
|
||||
} else {
|
||||
languageDetectionService.detectLanguage(model.uri).then(detectedLanguage => {
|
||||
|
||||
// TODOS:
|
||||
// once the model has been detected, stop detecting it; currently we detect on every new token which is very slow
|
||||
// dispose the model; i dont think editor.dispose() does this
|
||||
model.setLanguage(detectedLanguage ?? 'plaintext')
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const container = editor.getDomNode()
|
||||
const parentNode = container?.parentElement
|
||||
if (parentNode) {
|
||||
const height = Math.min(editor.getScrollHeight() + 1, MAX_HEIGHT);
|
||||
parentNode.style.height = `${height}px`;
|
||||
editor.layout();
|
||||
}
|
||||
|
||||
// Listen for content changes and update height
|
||||
const disposable = editor.onDidContentSizeChange(() => {
|
||||
const resize = () => {
|
||||
if (parentNode) {
|
||||
const height = Math.min(editor.getScrollHeight() + 1, MAX_HEIGHT);
|
||||
parentNode.style.height = `${height}px`;
|
||||
editor.layout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
resize()
|
||||
const disposable = editor.onDidContentSizeChange(() => { resize() });
|
||||
|
||||
return [disposable]
|
||||
}, [modelService, initValue, language])}
|
||||
|
|
|
|||
Loading…
Reference in a new issue