From 8a17c9246bf47eabf23d5bfcd332d193a3cce021 Mon Sep 17 00:00:00 2001 From: Mathew Pareles Date: Tue, 24 Dec 2024 17:23:27 -0800 Subject: [PATCH] language logic --- .../void/browser/react/src/util/inputs.tsx | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx index b247c279..37d7792b 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/inputs.tsx @@ -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])}