Merge pull request #125601 from cpsauer/line-height-multiple

Accept editor line height as multiple of font size
This commit is contained in:
Alexandru Dima 2021-06-11 09:49:17 +02:00 committed by GitHub
commit 750390dcd3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View file

@ -2471,13 +2471,14 @@ class EditorInlayHints extends BaseEditorOption<EditorOption.inlayHints, EditorI
//#region lineHeight
class EditorLineHeight extends EditorIntOption<EditorOption.lineHeight> {
class EditorLineHeight extends EditorFloatOption<EditorOption.lineHeight> {
constructor() {
super(
EditorOption.lineHeight, 'lineHeight',
EDITOR_FONT_DEFAULTS.lineHeight, 0, 150,
{ description: nls.localize('lineHeight', "Controls the line height. Use 0 to compute the line height from the font size.") }
EDITOR_FONT_DEFAULTS.lineHeight,
x => EditorFloatOption.clamp(x, 0, 150),
{ markdownDescription: nls.localize('lineHeight', "Controls the line height. \n - Use 0 to automatically compute the line height from the font size.\n - Values between 0 and 8 will be used as a multiplier with the font size.\n - Values greater than 8 will be used as effective values.") }
);
}

View file

@ -52,8 +52,15 @@ export class BareFontInfo {
*/
private static _create(fontFamily: string, fontWeight: string, fontSize: number, fontFeatureSettings: string, lineHeight: number, letterSpacing: number, zoomLevel: number, pixelRatio: number, ignoreEditorZoom: boolean): BareFontInfo {
if (lineHeight === 0) {
lineHeight = Math.round(GOLDEN_LINE_HEIGHT_RATIO * fontSize);
lineHeight = GOLDEN_LINE_HEIGHT_RATIO * fontSize;
} else if (lineHeight < MINIMUM_LINE_HEIGHT) {
// Values too small to be line heights in pixels are probably in ems. Accept them gracefully.
lineHeight = lineHeight * fontSize;
}
// Enforce integer, minimum constraints
lineHeight = Math.round(lineHeight);
if (lineHeight < MINIMUM_LINE_HEIGHT) {
lineHeight = MINIMUM_LINE_HEIGHT;
}