You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do I need to define any specific options to make it work in Monaco? I tried the following code. Decorations applied the line height and inline class name, but I don’t see any font related options being applied.
/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/// Enable automatic dark mode for accessibility.constdark=matchMedia('(prefers-color-scheme: dark)');monaco.editor.setTheme(dark.matches ? 'vs-dark' : 'vs-light');dark.addEventListener('change',()=>{monaco.editor.setTheme(dark.matches ? 'vs-dark' : 'vs-light');});constcontent=`function big(name: string): undefined { console.log("Hello", name, "!")}`;constmodel=monaco.editor.createModel(content,undefined,monaco.Uri.file('example.ts'));consteditor=monaco.editor.create(document.getElementById('editor')!,{automaticLayout: true,allowVariableFonts: true,allowVariableFontsInAccessibilityMode: true,allowVariableLineHeights: true,fontFamily: 'Arial',fontVariations: true,
model,wordWrap: 'on',wrappingStrategy: 'advanced',});// Make the model and editor available globally for fiddling in the console.Object.assign(globalThis,{
editor,
model,});constcollection=editor.createDecorationsCollection();functionupdateDecorations(){constnewDecorations: monaco.editor.IModelDeltaDecoration[]=[];for(constmatchofmodel.getValue().matchAll(/big/g)){constposition=model.getPositionAt(match.index);newDecorations.push({range: {startLineNumber: position.lineNumber,startColumn: position.column,endLineNumber: position.lineNumber,endColumn: position.column+match[0].length,},options: {inlineClassNameAffectsLetterSpacing: true,fontFamily: 'Monospace',fontStyle: 'italic',fontWeight: 'bold',fontSize: '40px',lineHeight: 56,inlineClassName: 'big'}});}collection.set(newDecorations);}model.onDidChangeContent(updateDecorations);updateDecorations();
The code was used in the playground introduced in #249616.
I have looked at the code and found the following. Currently it is only possible to set the font information with the VS Code API method createTextEditorDecorationType which modifies and appends CSS styling. The method createDecorationsCollection you are using does not modify the CSS style sheet and hence the font decorations you set are not visible. We need to maybe make the createDecorationsCollection method work with variable font info. I will create an issue about this. Currently variable font sizes are not usable in monaco editors.
Activity
remcohaszing commentedon May 28, 2025
Related:
aiday-mar commentedon Jun 30, 2025
A PR has been merged to implement this using the monaco editor API. There are still some things to do:
remcohaszing commentedon Jul 15, 2025
Do I need to define any specific options to make it work in Monaco? I tried the following code. Decorations applied the line height and inline class name, but I don’t see any font related options being applied.
The code was used in the playground introduced in #249616.
aiday-mar commentedon Jul 15, 2025
Hi Remco Haszing (@remcohaszing) thank you for your continuous support to the VS Code software. I will have look at the example you posted.
aiday-mar commentedon Jul 15, 2025
I have looked at the code and found the following. Currently it is only possible to set the font information with the VS Code API method
createTextEditorDecorationTypewhich modifies and appends CSS styling. The methodcreateDecorationsCollectionyou are using does not modify the CSS style sheet and hence the font decorations you set are not visible. We need to maybe make thecreateDecorationsCollectionmethod work with variable font info. I will create an issue about this. Currently variable font sizes are not usable in monaco editors.