Repository navigation
Description
Refs: #147067
- anyOS Anthony Kim (@anthonykim1)
- anyOS Benjamin Pasero (@bpasero)
- anyOS TylerLeonhardt
Complexity: 5
This iteration it has been made possible to define variable line heights in the the editor through editor decorations which override the default line height. There is a new property in the monaco.d.ts file called lineHeight in the IModelDecorationOptions which can be used to specify the line height for a specific range. The goal of this TPI is to verify that user interactions with editor lines having non-default line heights remain correct and to file issues otherwise. Some points to note are as follows:
- To simplify the code we have made the line height be applied only to the first line of the range of a decoration, not to the full range. This needs to be revised in the future.
- We have not yet surfaced the decoration
lineHeightproperty in thevscode.d.tsfor extensions to use. Please see below for how to define this property in an extension. - The line height for a specific line is defined by the maximum of the decorations line heights set on the given line
- The line heights are set per-editor, not per model
- This TPI only concerns variable line heights, not variable font-sizes and font-families, which I am currently working on.
Preparing the test
To test, the easiest to do is to start from the following PR: #246827. This PR surfaces the line height as a configurable property in the vscode.d.ts file and sets up the relevant code to convert the extension host decoration line height to the monaco editor line height. The PR also adds code to the inbuilt TypeScript extension so that lines that have class and interface names have line height 100, lines that have function signatures have line height 70 and lines that have method signatures have line height 30. If you run the code from the PR you should see something similar to the following:
Alternatively to test, you can add the change from the vscode.d.ts and the extHostTypeConverter.ts files from the PR above into the clean VS Code repo, run this new code and in OSS run a new extension which defines variable line heights.
I also invite you to find existing inbuilt monaco editors in VS Code (like for example the panel chat code blocks), set variable line heights on them, and test these cases!
Testing
The goal of this TPI is to break the user interaction with the editor when variable line heights are set on the editor. Think of settings and user actions that involve the editor line heights and which could break the variable line heights rendering. The following is a list of points I have already tested, but could serve as examples for other things to look out for:
- The lines are rendered correctly, not on top of each other, as you scroll or move the cursor
- The cursor extends over the whole active line and is correctly positioned vertically and horizontally
- Line is rendered correctly when two decorations setting line heights intersect
- Lines with variables heights are rendered correctly and without visible glitch/large on large files
- Ghost-text and whitespaces are rendered correctly and are aligned with the text in the variable line heights
- Codelens are positioned correctly above the variable line height as expected
- Selection backgrounds extend over the whole line height as expected
- Menu is correctly positioned
- Editor hover is correctly positioned above the given line
- IME is correctly positioned below line height
- Screen reader box is correctly positioned on variable line height
- Editor sticky scroll is correctly rendered
- Enable word wrap and resize the editor, make sure the line heights are rendered correctly
It would not hurt to test further the points above, especially if bugs have been introduced in the meantime and if you can push the above cases to their limits and find edge cases.
Known issues
- If the model of an editor with variable line heights is changed, then viewed with a diff editor, it may be that the left diff editor has no variable line heights while the right diff editor does. This would lead to diff editor lines not being aligned.
- When you have editor sticky scroll enabled, when you jump to a reference, the cursor may end up under the sticky scroll widget. This is happening because we show
maximumNumberOfStickyLines*lineHeightpixels above the cursor position when it jumps. This used to work when all the lines had the same height which is not the case anymore.
Thanks for testing!
Activity
[-]TPI: Variable line heights[/-][+]Test: variable line heights[/+]bpasero commentedon Apr 28, 2025
This is very cool 👏
anthonykim1 commentedon Apr 28, 2025
I love this feature, much easier to read files that are crammed/packed!
TylerLeonhardt commentedon Apr 28, 2025
Pretty cool! I added on to your sample in another branch that adds Markdown support:
intact-lemming...tyler/smiling-krill