Skip to content

Commit a66d813

Browse files
committed
Ensure Monaco measures fonts after the font is loaded
As soon as Monaco is instantiated, it measures various aspects of the chosen font. Since the playground fetches fonts, the fonts may not yet be available to be measured. After a bit, the fonts are loaded but Monaco's cached results are now out of date. We now trigger a remeasurement of the fonts after our fonts are available. For some reason, this has only been reported by people using Microsoft Edge, but theoretically it should occur in any browser. Perhaps there's something unique about Edge's text rendering? It also only occurs at certain original zoom levels — on my computer, it needed 125% zoom. Note that each zoom level has different font metrics, so changing the zoom once the font is loaded will work although the original incorrect metrics will still be cached. Fixes #1103
1 parent efd614b commit a66d813

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ui/frontend/editor/MonacoEditorCore.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { themeVsDarkPlus } from './rust_monaco_def';
88

99
import * as styles from './Editor.module.css';
1010

11+
async function remeasureFontWhenReady(fonts: FontFaceSet, font: string) {
12+
while (!fonts.check(font)) {
13+
await fonts.ready;
14+
}
15+
16+
monaco.editor.remeasureFonts();
17+
}
18+
1119
function useEditorProp<T>(
1220
editor: monaco.editor.IStandaloneCodeEditor | null,
1321
prop: T,
@@ -68,6 +76,8 @@ const MonacoEditorCore: React.FC<CommonEditorProps> = (props) => {
6876
});
6977
setEditor(editor);
7078

79+
remeasureFontWhenReady(document.fonts, nodeStyle.font);
80+
7181
editor.focus();
7282
}, []);
7383

0 commit comments

Comments
 (0)