Skip to content

Apply decoration lineHeight on all affected lines after line wrapping #249967

Description

In #194609 I implemented support for dynamic line heights using decorations. This works perfectly for us, but there are some unhandled things that were not relevant to us. Due to a change of priorities, this PR got abandoned. Now I have to get back to it.

Recently #241218 was merged. This also adds support for dynamic line heights using decorations. It was tested against some cases I never tested against, which is great. However, the behaviour is quite different.

There are two major differences:

  1. The implementation in Support dynamic line heights using decorations #194609 calculates the line heights of the lines after text wrapping. The implementation in Optimized: Allowing to define variable line heights #241218 calculates the line height of the unwrapped line, and applies this height to display lines that display the wrapped real line.
  2. The implementation in Support dynamic line heights using decorations #194609 applies the line height to all lines that are covered by the decoration range. The implementation in Optimized: Allowing to define variable line heights #241218 only applies to the first line of the decoration range.

I think these behaviours from #194609 are better. They match with what LibreOffice, Google Docs, and Microsoft Word do.

Would a PR be welcome to change this behaviour?

Activity

  1. aiday-mar commented on Jun 2, 2025

    @aiday-mar
    Collaborator

    Hi Remco Haszing (@remcohaszing) thank you for filing the issue. I am not sure I understand what you mean by point number 1. The line heights are set per view line in the file lineHeights.ts.

    For number 2, yes absolutely. This is a point we will work on and improve. We do not want to greatly change the current data structure we are using and expand on it.

  2. added
    editor-lines
    feature-request
    under-discussion
    on Jun 2, 2025
  3. vs-code-engineering commented on Jun 2, 2025

    @vs-code-engineering
    Contributor

    This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

    Happy Coding!

  4. remcohaszing commented on Jun 2, 2025

    @remcohaszing
    ContributorAuthor

    This is what it looks like with the current line heights implementation. A decoration that affects line height and font size is applied to a small selection on line 1. The line height is applied to the entirety of the unwrapped line 1, even the parts that aren’t part of the decoration.

    This is what it looks like in my original line heights implementation. The line height is applied only to the part of line 1 that’s affected by it after line wrapping.

    The following example code is used for both examples:

    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 = `Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1. Line 1.
    
    Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3. Line 3.
    `;
    
    const model = monaco.editor.createModel(content, undefined, monaco.Uri.file('example.txt'));
    
    const editor = monaco.editor.create(document.getElementById('editor'), {
    	automaticLayout: true,
    	autoIndent: 'none',
    	accessibilitySupport: 'off',
    	accessibilityPageSize: 1,
    	autoClosingBrackets: 'never',
    	autoClosingComments: 'never',
    	autoClosingDelete: 'never',
    	autoClosingOvertype: 'never',
    	autoClosingQuotes: 'never',
    	autoSurround: 'never',
    	bracketPairColorization: { enabled: false },
    	columnSelection: false,
    	contextmenu: false,
    	definitionLinkOpensInPeek: false,
    	detectIndentation: false,
    	disableLayerHinting: true,
    	disableMonospaceOptimizations: true,
    	fixedOverflowWidgets: false,
    	inDiffEditor: false,
    	largeFileOptimizations: true,
    	linkedEditing: false,
    	links: false,
    	matchBrackets: 'never',
    	parameterHints: { enabled: false },
    	model,
    	minimap: {
    		enabled: false,
    		side: 'left',
    		maxColumn: 5,
    		showSlider: 'always',
    		renderCharacters: false,
    		scale: 100
    	},
    	fontFamily: 'Arial, Arimo, sans-serif, ui-sans-serif',
    	fontLigatures: false,
    	fontVariations: false,
    	fontWeight: 'normal',
    	fontSize: 14,
    	lineHeight: 0,
    	letterSpacing: 0,
    
    
    	// Wrap lines at viewport width
    	wordWrap: 'on',
    	// Advanced wrapping strategy - necessary to ensure line wraps with variable width fonts
    	wrappingStrategy: 'advanced',
    	wordBreak: 'keepAll',
    	wrappingIndent: 'none',
    });
    
    const bigCollection = editor.createDecorationsCollection();
    
    editor.addAction({
    	keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyB],
    	id: 'bold',
    	label: 'Bold',
    	run(editor) {
    		const selections = editor.getSelections();
    		if (!selections) {
    			return;
    		}
    
    		bigCollection.set(selections.map((selection) => (
    			{
    				range: selection,
    				options: {
    					inlineClassNameAffectsLetterSpacing: true,
    					lineHeight: 56,
    					inlineClassName: 'big'
    				}
    			}
    		)));
    	},
    });
    .big {
    	font-size: 32px;
    }

    For comparison, this is what it looks like in LibreOffice. Google Docs and Microsoft Word do the same.

  5. aiday-mar commented on Jun 3, 2025

    @aiday-mar
    Collaborator

    Hi thanks for the clarification. I see thanks, I will discuss this with my team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

editor-linesfeature-requestunder-discussion

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions