From 6f1f5303e2b619f2a2c60582c98c3397ef5e1dda Mon Sep 17 00:00:00 2001 From: charles-ramos Date: Thu, 28 May 2026 15:02:16 -0300 Subject: [PATCH] fix: monaco editor --- .../CodeEditor/B4aCodeEditorImpl.react.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/components/CodeEditor/B4aCodeEditorImpl.react.js b/src/components/CodeEditor/B4aCodeEditorImpl.react.js index 178a52a53..15a71d1a6 100644 --- a/src/components/CodeEditor/B4aCodeEditorImpl.react.js +++ b/src/components/CodeEditor/B4aCodeEditorImpl.react.js @@ -77,6 +77,29 @@ const B4aCodeEditorImpl = forwardRef( editorRef.current = editor; monacoRef.current = monaco; + const remeasureAndLayout = () => { + if (editorRef.current !== editor || monacoRef.current !== monaco) { + return; + } + if (typeof monaco.editor?.remeasureFonts === 'function') { + monaco.editor.remeasureFonts(); + } + editor.layout(); + }; + + // Monaco can cache character widths before async webfonts finish loading, + // which makes the caret drift horizontally on some machines/browsers. + remeasureAndLayout(); + if (typeof document !== 'undefined' && document.fonts?.ready) { + document.fonts.ready.then(() => { + if (typeof window !== 'undefined' && typeof window.requestAnimationFrame === 'function') { + window.requestAnimationFrame(remeasureAndLayout); + return; + } + remeasureAndLayout(); + }); + } + if (monaco.languages.typescript) { const jsDefaults = monaco.languages.typescript.javascriptDefaults; jsDefaults.setDiagnosticsOptions({