File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed
Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -83,10 +83,28 @@ function SandcastleEditor({
8383 const {
8484 settings : { fontFamily, fontSize, fontLigatures } ,
8585 } = useContext ( SettingsContext ) ;
86+ const documentRef = useRef ( document ) ;
8687 useEffect ( ( ) => {
87- internalEditorRef . current ?. updateOptions ( {
88- fontFamily : availableFonts [ fontFamily ] ?. cssValue ?? "Droid Sans Mono" ,
89- } ) ;
88+ const cssName = availableFonts [ fontFamily ] ?. cssValue ?? "Droid Sans Mono" ;
89+ const fontFace = [ ...documentRef . current . fonts . values ( ) ] . find (
90+ ( font ) => font . family === cssName && font . weight === "400" ,
91+ ) ;
92+ if ( fontFace ?. status !== "loaded" ) {
93+ // Monaco needs to check the size of the font for things like cursor position
94+ // and variable highlighting. If it does this check before the font has loaded
95+ // it will get the wrong size and may be horribly offset especially with ligatures
96+ // https://github.com/microsoft/monaco-editor/issues/392
97+ documentRef . current . fonts . load ( `1rem ${ cssName } ` ) . then ( ( ) => {
98+ internalEditorRef . current ?. updateOptions ( {
99+ fontFamily : cssName ,
100+ } ) ;
101+ monaco . editor . remeasureFonts ( ) ;
102+ } ) ;
103+ } else {
104+ internalEditorRef . current ?. updateOptions ( {
105+ fontFamily : cssName ,
106+ } ) ;
107+ }
90108 } , [ fontFamily ] ) ;
91109 useEffect ( ( ) => {
92110 internalEditorRef . current ?. updateOptions ( {
You can’t perform that action at this time.
0 commit comments