Skip to content

Support variable fonts in the editor #237346

Closed

Description

Related to #147067

The issue above will be used to track variable line heights only

This issue is about tracking the feature of variable fonts (font-family, font-size etc) in the editor

Activity

  1. added
    editor-core
    feature-request
    on Jan 6, 2025
  2. remcohaszing commented on May 28, 2025

    @remcohaszing
    Contributor
  3. aiday-mar commented on Jun 30, 2025

    @aiday-mar
    CollaboratorAuthor

    A PR has been merged to implement this using the monaco editor API. There are still some things to do:

    • Make the line breaks break at the correct positions
    • Add VS Code API to allow users to define variable font sizes
  4. remcohaszing commented on Jul 15, 2025

    @remcohaszing
    Contributor

    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.
    const dark = 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');
    });
    
    const content = `
    function big(name: string): undefined {
    	console.log("Hello", name, "!")
    }
    `;
    
    const model = monaco.editor.createModel(content, undefined, monaco.Uri.file('example.ts'));
    
    const editor = 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,
    });
    
    const collection = editor.createDecorationsCollection();
    
    function updateDecorations() {
    	const newDecorations: monaco.editor.IModelDeltaDecoration[] = [];
    
    	for (const match of model.getValue().matchAll(/big/g)) {
    		const position = 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.

  5. aiday-mar commented on Jul 15, 2025

    @aiday-mar
    CollaboratorAuthor

    Hi Remco Haszing (@remcohaszing) thank you for your continuous support to the VS Code software. I will have look at the example you posted.

  6. aiday-mar commented on Jul 15, 2025

    @aiday-mar
    CollaboratorAuthor

    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.

  7. locked and limited conversation to collaborators on Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-corefeature-requeston-testplan

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions