From a8ceb42514d0dbce902bfc002a672a6bee593f33 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:08:12 +0100 Subject: [PATCH 1/7] using a number value for the font size instead of a string value --- src/grammar/grammar.ts | 2 +- src/main.ts | 2 +- src/tests/grammar.test.ts | 8 +- src/tests/themes.test.ts | 189 +++++++++++++++++++------------------- src/theme.ts | 30 +++--- 5 files changed, 115 insertions(+), 116 deletions(-) diff --git a/src/grammar/grammar.ts b/src/grammar/grammar.ts index bc324b6..e152a73 100644 --- a/src/grammar/grammar.ts +++ b/src/grammar/grammar.ts @@ -1124,7 +1124,7 @@ export class FontInfo implements IFontInfo { public startIndex: number, public endIndex: number, public fontFamily: string | null, - public fontSize: string | null, + public fontSize: number | null, public lineHeight: number | null ) { } diff --git a/src/main.ts b/src/main.ts index 6065917..6d27764 100644 --- a/src/main.ts +++ b/src/main.ts @@ -273,7 +273,7 @@ export interface IFontInfo { /** * Font size specification */ - readonly fontSize: string | null; + readonly fontSize: number | null; /** * Line height specification diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index c9a52ce..f948e87 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -150,7 +150,7 @@ test('Fonts are correctly set', async function () { scope: 'bar.test', settings: { fontFamily: 'monospace', - fontSize: '12px', + fontSize: 1.2, lineHeight: 20 } }] @@ -163,7 +163,7 @@ test('Fonts are correctly set', async function () { ] }); const result = grammar.tokenizeLine2('bar hello', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", "12px", 20)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 1.3)]); } finally { registry.dispose(); } @@ -177,7 +177,7 @@ test('Fonts are correctly set 2', async function () { scope: 'entity.name.function.ts', settings: { fontFamily: 'Times New Roman', - fontSize: '20px', + fontSize: 1.3, lineHeight: 40 } }] @@ -190,7 +190,7 @@ test('Fonts are correctly set 2', async function () { ] }); const result = grammar.tokenizeLine2('function g() {}', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', "20px", 40)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.2, 1.3)]); } finally { registry.dispose(); } diff --git a/src/tests/themes.test.ts b/src/tests/themes.test.ts index 35fa740..9da1ebc 100644 --- a/src/tests/themes.test.ts +++ b/src/tests/themes.test.ts @@ -17,7 +17,6 @@ import { import { ThemeTest } from './themeTest'; import { getOniguruma } from './onigLibs'; import { Resolver, IGrammarRegistration, ILanguageRegistration } from './resolver'; -import { EncodedTokenAttributes } from '../encodedTokenAttributes'; import { strArrCmp, strcmp } from '../utils'; import { parsePLIST } from '../plist'; @@ -302,19 +301,19 @@ test('Theme parsing can parse', () => { }); let expected = [ - new ParsedThemeRule('', null, 0, FontStyle.NotSet, '#F8F8F2', '#272822', '', '', 0), - new ParsedThemeRule('source', null, 1, FontStyle.NotSet, null, '#100000', '', '', 0), - new ParsedThemeRule('something', null, 1, FontStyle.NotSet, null, '#100000', '', '', 0), - new ParsedThemeRule('bar', null, 2, FontStyle.NotSet, null, '#010000', '', '', 0), - new ParsedThemeRule('baz', null, 2, FontStyle.NotSet, null, '#010000', '', '', 0), - new ParsedThemeRule('bar', ['selector', 'source.css'], 3, FontStyle.Bold, null, null, '', '', 0), - new ParsedThemeRule('constant', null, 4, FontStyle.Italic, '#ff0000', null, '', '', 0), - new ParsedThemeRule('constant.numeric', null, 5, FontStyle.NotSet, '#00ff00', null, '', '', 0), - new ParsedThemeRule('constant.numeric.hex', null, 6, FontStyle.Bold, null, null, '', '', 0), - new ParsedThemeRule('constant.numeric.oct', null, 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null, '', '', 0), - new ParsedThemeRule('constant.numeric.bin', null, 8, FontStyle.Bold | FontStyle.Strikethrough, null, null, '', '', 0), - new ParsedThemeRule('constant.numeric.dec', null, 9, FontStyle.None, '#0000ff', null, '', '', 0), - new ParsedThemeRule('foo', null, 10, FontStyle.None, '#CFA', null, '', '', 0), + new ParsedThemeRule('', null, 0, FontStyle.NotSet, '#F8F8F2', '#272822', '', 0, 0), + new ParsedThemeRule('source', null, 1, FontStyle.NotSet, null, '#100000', '', 0, 0), + new ParsedThemeRule('something', null, 1, FontStyle.NotSet, null, '#100000', '', 0, 0), + new ParsedThemeRule('bar', null, 2, FontStyle.NotSet, null, '#010000', '', 0, 0), + new ParsedThemeRule('baz', null, 2, FontStyle.NotSet, null, '#010000', '', 0, 0), + new ParsedThemeRule('bar', ['selector', 'source.css'], 3, FontStyle.Bold, null, null, '', 0, 0), + new ParsedThemeRule('constant', null, 4, FontStyle.Italic, '#ff0000', null, '', 0, 0), + new ParsedThemeRule('constant.numeric', null, 5, FontStyle.NotSet, '#00ff00', null, '', 0, 0), + new ParsedThemeRule('constant.numeric.hex', null, 6, FontStyle.Bold, null, null, '', 0, 0), + new ParsedThemeRule('constant.numeric.oct', null, 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null, '', 0, 0), + new ParsedThemeRule('constant.numeric.bin', null, 8, FontStyle.Bold | FontStyle.Strikethrough, null, null, '', 0, 0), + new ParsedThemeRule('constant.numeric.dec', null, 9, FontStyle.None, '#0000ff', null, '', 0, 0), + new ParsedThemeRule('foo', null, 10, FontStyle.None, '#CFA', null, '', 0, 0), ]; assert.deepStrictEqual(actual, expected); @@ -365,15 +364,15 @@ test('Theme resolving always has defaults', () => { const _B = colorMap.getId('#ffffff'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving respects incoming defaults 1', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, null, '', '', 0) + new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, null, '', 0, 0) ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -382,15 +381,15 @@ test('Theme resolving respects incoming defaults 1', () => { const _B = colorMap.getId('#ffffff'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving respects incoming defaults 2', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.None, null, null, '', '', 0) + new ParsedThemeRule('', null, -1, FontStyle.None, null, null, '', 0, 0) ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -399,15 +398,15 @@ test('Theme resolving respects incoming defaults 2', () => { const _B = colorMap.getId('#ffffff'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving respects incoming defaults 3', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.Bold, null, null, '', '', 0) + new ParsedThemeRule('', null, -1, FontStyle.Bold, null, null, '', 0, 0) ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -416,15 +415,15 @@ test('Theme resolving respects incoming defaults 3', () => { const _B = colorMap.getId('#ffffff'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.Bold, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.Bold, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving respects incoming defaults 4', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#ff0000', null, '', '', 0) + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#ff0000', null, '', 0, 0) ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -433,15 +432,15 @@ test('Theme resolving respects incoming defaults 4', () => { const _B = colorMap.getId('#ffffff'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving respects incoming defaults 5', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, '#ff0000', '', '', 0) + new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, '#ff0000', '', 0, 0) ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -450,17 +449,17 @@ test('Theme resolving respects incoming defaults 5', () => { const _B = colorMap.getId('#ff0000'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving can merge incoming defaults', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, '#ff0000', '', '', 0), - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#00ff00', null, '', '', 0), - new ParsedThemeRule('', null, -1, FontStyle.Bold, null, null, '', '', 0), + new ParsedThemeRule('', null, -1, FontStyle.NotSet, null, '#ff0000', '', 0, 0), + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#00ff00', null, '', 0, 0), + new ParsedThemeRule('', null, -1, FontStyle.Bold, null, null, '', 0, 0), ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -469,16 +468,16 @@ test('Theme resolving can merge incoming defaults', () => { const _B = colorMap.getId('#ff0000'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.Bold, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.Bold, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) ); assertThemeEqual(actual, expected); }); test('Theme resolving defaults are inherited', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', '', 0), - new ParsedThemeRule('var', null, -1, FontStyle.NotSet, '#ff0000', null, '', '', 0) + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', 0, 0), + new ParsedThemeRule('var', null, -1, FontStyle.NotSet, '#ff0000', null, '', 0, 0) ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -488,9 +487,9 @@ test('Theme resolving defaults are inherited', () => { const _C = colorMap.getId('#ff0000'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.NotSet, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) }) ); assertThemeEqual(actual, expected); @@ -498,9 +497,9 @@ test('Theme resolving defaults are inherited', () => { test('Theme resolving same rules get merged', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', '', 0), - new ParsedThemeRule('var', null, 1, FontStyle.Bold, null, null, '', '', 0), - new ParsedThemeRule('var', null, 0, FontStyle.NotSet, '#ff0000', null, '', '', 0), + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', 0, 0), + new ParsedThemeRule('var', null, 1, FontStyle.Bold, null, null, '', 0, 0), + new ParsedThemeRule('var', null, 0, FontStyle.NotSet, '#ff0000', null, '', 0, 0), ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -510,9 +509,9 @@ test('Theme resolving same rules get merged', () => { const _C = colorMap.getId('#ff0000'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) }) ); assertThemeEqual(actual, expected); @@ -520,9 +519,9 @@ test('Theme resolving same rules get merged', () => { test('Theme resolving rules are inherited 1', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', '', 0), - new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#ff0000', null, '', '', 0), - new ParsedThemeRule('var.identifier', null, -1, FontStyle.NotSet, '#00ff00', null, '', '', 0), + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', 0, 0), + new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#ff0000', null, '', 0, 0), + new ParsedThemeRule('var.identifier', null, -1, FontStyle.NotSet, '#00ff00', null, '', 0, 0), ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -533,10 +532,10 @@ test('Theme resolving rules are inherited 1', () => { const _D = colorMap.getId('#00ff00'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'identifier': new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'identifier': new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) }) }) ); @@ -545,14 +544,14 @@ test('Theme resolving rules are inherited 1', () => { test('Theme resolving rules are inherited 2', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', '', 0), - new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#ff0000', null, '', '', 0), - new ParsedThemeRule('var.identifier', null, -1, FontStyle.NotSet, '#00ff00', null, '', '', 0), - new ParsedThemeRule('constant', null, 4, FontStyle.Italic, '#100000', null, '', '', 0), - new ParsedThemeRule('constant.numeric', null, 5, FontStyle.NotSet, '#200000', null, '', '', 0), - new ParsedThemeRule('constant.numeric.hex', null, 6, FontStyle.Bold, null, null, '', '', 0), - new ParsedThemeRule('constant.numeric.oct', null, 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null, '', '', 0), - new ParsedThemeRule('constant.numeric.dec', null, 8, FontStyle.None, '#300000', null, '', '', 0), + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', 0, 0), + new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#ff0000', null, '', 0, 0), + new ParsedThemeRule('var.identifier', null, -1, FontStyle.NotSet, '#00ff00', null, '', 0, 0), + new ParsedThemeRule('constant', null, 4, FontStyle.Italic, '#100000', null, '', 0, 0), + new ParsedThemeRule('constant.numeric', null, 5, FontStyle.NotSet, '#200000', null, '', 0, 0), + new ParsedThemeRule('constant.numeric.hex', null, 6, FontStyle.Bold, null, null, '', 0, 0), + new ParsedThemeRule('constant.numeric.oct', null, 7, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, null, null, '', 0, 0), + new ParsedThemeRule('constant.numeric.dec', null, 8, FontStyle.None, '#300000', null, '', 0, 0), ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -566,16 +565,16 @@ test('Theme resolving rules are inherited 2', () => { const _G = colorMap.getId('#00ff00'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _F, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'identifier': new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _G, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)) + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'var': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Bold, _F, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'identifier': new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Bold, _G, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)) }), - 'constant': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Italic, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'numeric': new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Italic, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { - 'hex': new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)), - 'oct': new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)), - 'dec': new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.None, _E, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)), + 'constant': new ThemeTrieElement(new ThemeTrieElementRule(1, null, FontStyle.Italic, _C, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'numeric': new ThemeTrieElement(new ThemeTrieElementRule(2, null, FontStyle.Italic, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { + 'hex': new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)), + 'oct': new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)), + 'dec': new ThemeTrieElement(new ThemeTrieElementRule(3, null, FontStyle.None, _E, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)), }) }) }) @@ -585,11 +584,11 @@ test('Theme resolving rules are inherited 2', () => { test('Theme resolving rules with parent scopes', () => { let actual = Theme.createFromParsedTheme([ - new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', '', 0), - new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#100000', null, '', '', 0), - new ParsedThemeRule('var.identifier', null, -1, FontStyle.NotSet, '#200000', null, '', '', 0), - new ParsedThemeRule('var', ['source.css'], 1, FontStyle.Italic, '#300000', null, '', '', 0), - new ParsedThemeRule('var', ['source.css'], 2, FontStyle.Underline, null, null, '', '', 0), + new ParsedThemeRule('', null, -1, FontStyle.NotSet, '#F8F8F2', '#272822', '', 0, 0), + new ParsedThemeRule('var', null, -1, FontStyle.Bold, '#100000', null, '', 0, 0), + new ParsedThemeRule('var.identifier', null, -1, FontStyle.NotSet, '#200000', null, '', 0, 0), + new ParsedThemeRule('var', ['source.css'], 1, FontStyle.Italic, '#300000', null, '', 0, 0), + new ParsedThemeRule('var', ['source.css'], 2, FontStyle.Underline, null, null, '', 0, 0), ]); let colorMap = new ColorMap(); const _NUMBER_NOT_SET = 0; @@ -601,15 +600,15 @@ test('Theme resolving rules with parent scopes', () => { const _E = colorMap.getId('#200000'); let expected = new Theme( colorMap, - new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), [], { + new StyleAttributes(FontStyle.None, _A, _B, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + new ThemeTrieElement(new ThemeTrieElementRule(0, null, FontStyle.NotSet, _NUMBER_NOT_SET, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), [], { 'var': new ThemeTrieElement( - new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, 0, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - [new ThemeTrieElementRule(1, ['source.css'], FontStyle.Underline, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)], + new ThemeTrieElementRule(1, null, FontStyle.Bold, _C, 0, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + [new ThemeTrieElementRule(1, ['source.css'], FontStyle.Underline, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)], { 'identifier': new ThemeTrieElement( - new ThemeTrieElementRule(2, null, FontStyle.Bold, _E, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET), - [new ThemeTrieElementRule(1, ['source.css'], FontStyle.Underline, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET)] + new ThemeTrieElementRule(2, null, FontStyle.Bold, _E, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET), + [new ThemeTrieElementRule(1, ['source.css'], FontStyle.Underline, _D, _NUMBER_NOT_SET, _STRING_NOT_SET, _NUMBER_NOT_SET, _NUMBER_NOT_SET)] ) } ) @@ -719,12 +718,12 @@ test('Theme resolving issue #38: ignores rules with invalid colors', () => { }); let expected = [ - new ParsedThemeRule('', null, 0, FontStyle.NotSet, '#cccccc', '#222222', '', '', 0), - new ParsedThemeRule('variable', null, 1, FontStyle.None, null, null, '', '', 0), - new ParsedThemeRule('variable.parameter', null, 2, FontStyle.Italic, null, null, '', '', 0), - new ParsedThemeRule('support.other.variable', null, 3, FontStyle.None, null, null, '', '', 0), - new ParsedThemeRule('variable.other', null, 4, FontStyle.None, null, null, '', '', 0), - new ParsedThemeRule('variable.parameter.function.coffee', null, 5, FontStyle.Italic, '#F9D423', null, '', '', 0), + new ParsedThemeRule('', null, 0, FontStyle.NotSet, '#cccccc', '#222222', '', 0, 0), + new ParsedThemeRule('variable', null, 1, FontStyle.None, null, null, '', 0, 0), + new ParsedThemeRule('variable.parameter', null, 2, FontStyle.Italic, null, null, '', 0, 0), + new ParsedThemeRule('support.other.variable', null, 3, FontStyle.None, null, null, '', 0, 0), + new ParsedThemeRule('variable.other', null, 4, FontStyle.None, null, null, '', 0, 0), + new ParsedThemeRule('variable.parameter.function.coffee', null, 5, FontStyle.Italic, '#F9D423', null, '', 0, 0), ]; assert.deepStrictEqual(actual, expected); @@ -754,13 +753,13 @@ test('Theme resolving issue #35: Trailing comma in a tmTheme scope selector', () }); let expected = [ - new ParsedThemeRule('', null, 0, FontStyle.NotSet, '#EFEFEF', '#25292C', '', '', 0), - new ParsedThemeRule('meta.at-rule.return.scss', null, 1, FontStyle.NotSet, '#CC7832', null, '', '', 0), - new ParsedThemeRule('punctuation.definition', ['meta.at-rule.return.scss'], 1, FontStyle.NotSet, '#CC7832', null, '', '', 0), - new ParsedThemeRule('meta.at-rule.else.scss', null, 1, FontStyle.NotSet, '#CC7832', null, '', '', 0), - new ParsedThemeRule('punctuation.definition', ['meta.at-rule.else.scss'], 1, FontStyle.NotSet, '#CC7832', null, '', '', 0), - new ParsedThemeRule('meta.at-rule.if.scss', null, 1, FontStyle.NotSet, '#CC7832', null, '', '', 0), - new ParsedThemeRule('punctuation.definition', ['meta.at-rule.if.scss'], 1, FontStyle.NotSet, '#CC7832', null, '', '', 0), + new ParsedThemeRule('', null, 0, FontStyle.NotSet, '#EFEFEF', '#25292C', '', 0, 0), + new ParsedThemeRule('meta.at-rule.return.scss', null, 1, FontStyle.NotSet, '#CC7832', null, '', 0, 0), + new ParsedThemeRule('punctuation.definition', ['meta.at-rule.return.scss'], 1, FontStyle.NotSet, '#CC7832', null, '', 0, 0), + new ParsedThemeRule('meta.at-rule.else.scss', null, 1, FontStyle.NotSet, '#CC7832', null, '', 0, 0), + new ParsedThemeRule('punctuation.definition', ['meta.at-rule.else.scss'], 1, FontStyle.NotSet, '#CC7832', null, '', 0, 0), + new ParsedThemeRule('meta.at-rule.if.scss', null, 1, FontStyle.NotSet, '#CC7832', null, '', 0, 0), + new ParsedThemeRule('punctuation.definition', ['meta.at-rule.if.scss'], 1, FontStyle.NotSet, '#CC7832', null, '', 0, 0), ]; assert.deepStrictEqual(actual, expected); diff --git a/src/theme.ts b/src/theme.ts index 2b22a99..037ff0e 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -83,7 +83,7 @@ export type ScopePattern = string; /** * A TextMate theme. */ - export interface IRawTheme { +export interface IRawTheme { readonly name?: string; readonly settings: IRawThemeSetting[]; } @@ -91,7 +91,7 @@ export type ScopePattern = string; /** * A single theme setting. */ - export interface IRawThemeSetting { +export interface IRawThemeSetting { readonly name?: string; readonly scope?: ScopePattern | ScopePattern[]; readonly settings: { @@ -99,7 +99,7 @@ export type ScopePattern = string; readonly foreground?: string; readonly background?: string; readonly fontFamily?: string; - readonly fontSize?: string; + readonly fontSize?: number; readonly lineHeight?: number; }; } @@ -219,7 +219,7 @@ export class StyleAttributes { public readonly foregroundId: number, public readonly backgroundId: number, public readonly fontFamily: string, - public readonly fontSize: string, + public readonly fontSize: number, public readonly lineHeight: number ) { } } @@ -299,8 +299,8 @@ export function parseTheme(source: IRawTheme | undefined): ParsedThemeRule[] { fontFamily = entry.settings.fontFamily; } - let fontSize: string = ''; - if (typeof entry.settings.fontSize === 'string') { + let fontSize: number = 0; + if (typeof entry.settings.fontSize === 'number') { fontSize = entry.settings.fontSize; } @@ -347,7 +347,7 @@ export class ParsedThemeRule { public readonly foreground: string | null, public readonly background: string | null, public readonly fontFamily: string, - public readonly fontSize: string, + public readonly fontSize: number, public readonly lineHeight: number, ) { } @@ -409,7 +409,7 @@ function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[], _colorMap: let defaultForeground = '#000000'; let defaultBackground = '#ffffff'; let defaultFontFamily = ''; - let defaultFontSize = ''; + let defaultFontSize = 0; let defaultLineHeight = 0; while (parsedThemeRules.length >= 1 && parsedThemeRules[0].scope === '') { @@ -517,7 +517,7 @@ export class ThemeTrieElementRule { foreground: number; background: number; fontFamily: string; - fontSize: string; + fontSize: number; lineHeight: number; constructor( @@ -527,7 +527,7 @@ export class ThemeTrieElementRule { foreground: number, background: number, fontFamily: string, - fontSize: string, + fontSize: number, lineHeight: number ) { this.scopeDepth = scopeDepth; @@ -567,7 +567,7 @@ export class ThemeTrieElementRule { foreground: number, background: number, fontFamily: string, - fontSize: string, + fontSize: number, lineHeight: number ): void { if (this.scopeDepth > scopeDepth) { @@ -588,7 +588,7 @@ export class ThemeTrieElementRule { if (fontFamily !== '') { this.fontFamily = fontFamily; } - if (fontSize !== '') { + if (fontSize !== 0) { this.fontSize = fontSize; } if (lineHeight !== 0) { @@ -693,7 +693,7 @@ export class ThemeTrieElement { foreground: number, background: number, fontFamily: string, - fontSize: string, + fontSize: number, lineHeight: number, ): void { if (scope === '') { @@ -730,7 +730,7 @@ export class ThemeTrieElement { foreground: number, background: number, fontFamily: string, - fontSize: string, + fontSize: number, lineHeight: number ): void { @@ -766,7 +766,7 @@ export class ThemeTrieElement { if (fontFamily === '') { fontFamily = this._mainRule.fontFamily; } - if (fontSize === '') { + if (fontSize === 0) { fontSize = this._mainRule.fontSize; } if (lineHeight === 0) { From 63dcc2e7a6edaeadc0d874bf1a66064529ce5d40 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:10:23 +0100 Subject: [PATCH 2/7] changing the tests values --- src/tests/grammar.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index f948e87..c67898f 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -151,7 +151,7 @@ test('Fonts are correctly set', async function () { settings: { fontFamily: 'monospace', fontSize: 1.2, - lineHeight: 20 + lineHeight: 3 } }] }); @@ -178,7 +178,7 @@ test('Fonts are correctly set 2', async function () { settings: { fontFamily: 'Times New Roman', fontSize: 1.3, - lineHeight: 40 + lineHeight: 3 } }] }); From 5cfbabd26fc8a336561a0c540e9c70e8510f6e03 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:12:27 +0100 Subject: [PATCH 3/7] fixing the tests --- src/tests/grammar.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index c67898f..8cda262 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -163,7 +163,7 @@ test('Fonts are correctly set', async function () { ] }); const result = grammar.tokenizeLine2('bar hello', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 1.3)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 3)]); } finally { registry.dispose(); } @@ -190,7 +190,7 @@ test('Fonts are correctly set 2', async function () { ] }); const result = grammar.tokenizeLine2('function g() {}', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.2, 1.3)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.3, 3)]); } finally { registry.dispose(); } From 9db25495a5905b86dde6267eb63018cd90a6ac78 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:31:26 +0100 Subject: [PATCH 4/7] renaming to multiplier --- src/grammar/grammar.ts | 12 ++--- src/main.ts | 4 +- src/tests/grammar.test.ts | 8 ++-- src/theme.ts | 98 +++++++++++++++++++-------------------- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/grammar/grammar.ts b/src/grammar/grammar.ts index e152a73..59851fd 100644 --- a/src/grammar/grammar.ts +++ b/src/grammar/grammar.ts @@ -1124,14 +1124,14 @@ export class FontInfo implements IFontInfo { public startIndex: number, public endIndex: number, public fontFamily: string | null, - public fontSize: number | null, - public lineHeight: number | null + public fontSizeMultiplier: number | null, + public lineHeightMultiplier: number | null ) { } optionsEqual(other: IFontInfo): boolean { return this.fontFamily === other.fontFamily - && this.fontSize === other.fontSize - && this.lineHeight === other.lineHeight; + && this.fontSizeMultiplier === other.fontSizeMultiplier + && this.lineHeightMultiplier === other.lineHeightMultiplier; } } @@ -1157,8 +1157,8 @@ export class LineFonts { return; } const fontFamily = styleAttributes.fontFamily; - const fontSize = styleAttributes.fontSize; - const lineHeight = styleAttributes.lineHeight; + const fontSize = styleAttributes.fontSizeMultiplier; + const lineHeight = styleAttributes.lineHeightMultiplier; if (!fontFamily && !fontSize && !lineHeight) { this._lastIndex = endIndex; return; diff --git a/src/main.ts b/src/main.ts index 6d27764..c8f2c3a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -273,12 +273,12 @@ export interface IFontInfo { /** * Font size specification */ - readonly fontSize: number | null; + readonly fontSizeMultiplier: number | null; /** * Line height specification */ - readonly lineHeight: number | null; + readonly lineHeightMultiplier: number | null; } export interface IToken { diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index 8cda262..dcc0d35 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -150,8 +150,8 @@ test('Fonts are correctly set', async function () { scope: 'bar.test', settings: { fontFamily: 'monospace', - fontSize: 1.2, - lineHeight: 3 + fontSizeMultiplier: 1.2, + lineHeightMultiplier: 3 } }] }); @@ -177,8 +177,8 @@ test('Fonts are correctly set 2', async function () { scope: 'entity.name.function.ts', settings: { fontFamily: 'Times New Roman', - fontSize: 1.3, - lineHeight: 3 + fontSizeMultiplier: 1.3, + lineHeightMultiplier: 3 } }] }); diff --git a/src/theme.ts b/src/theme.ts index 037ff0e..57693fa 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -27,7 +27,7 @@ export class Theme { private readonly _colorMap: ColorMap, private readonly _defaults: StyleAttributes, private readonly _root: ThemeTrieElement - ) {} + ) { } public getColorMap(): string[] { return this._colorMap.getColorMap(); @@ -56,8 +56,8 @@ export class Theme { effectiveRule.foreground, effectiveRule.background, effectiveRule.fontFamily, - effectiveRule.fontSize, - effectiveRule.lineHeight + effectiveRule.fontSizeMultiplier, + effectiveRule.lineHeightMultiplier ); } } @@ -99,8 +99,8 @@ export interface IRawThemeSetting { readonly foreground?: string; readonly background?: string; readonly fontFamily?: string; - readonly fontSize?: number; - readonly lineHeight?: number; + readonly fontSizeMultiplier?: number; + readonly lineHeightMultiplier?: number; }; } @@ -125,7 +125,7 @@ export class ScopeStack { constructor( public readonly parent: ScopeStack | null, public readonly scopeName: ScopeName - ) {} + ) { } public push(scopeName: ScopeName): ScopeStack { return new ScopeStack(this, scopeName); @@ -219,8 +219,8 @@ export class StyleAttributes { public readonly foregroundId: number, public readonly backgroundId: number, public readonly fontFamily: string, - public readonly fontSize: number, - public readonly lineHeight: number + public readonly fontSizeMultiplier: number, + public readonly lineHeightMultiplier: number ) { } } @@ -300,13 +300,13 @@ export function parseTheme(source: IRawTheme | undefined): ParsedThemeRule[] { } let fontSize: number = 0; - if (typeof entry.settings.fontSize === 'number') { - fontSize = entry.settings.fontSize; + if (typeof entry.settings.fontSizeMultiplier === 'number') { + fontSize = entry.settings.fontSizeMultiplier; } let lineHeight: number = 0; - if (typeof entry.settings.lineHeight === 'number') { - lineHeight = entry.settings.lineHeight; + if (typeof entry.settings.lineHeightMultiplier === 'number') { + lineHeight = entry.settings.lineHeightMultiplier; } for (let j = 0, lenJ = scopes.length; j < lenJ; j++) { @@ -347,8 +347,8 @@ export class ParsedThemeRule { public readonly foreground: string | null, public readonly background: string | null, public readonly fontFamily: string, - public readonly fontSize: number, - public readonly lineHeight: number, + public readonly fontSizeMultiplier: number, + public readonly lineHeightMultiplier: number, ) { } } @@ -426,11 +426,11 @@ function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[], _colorMap: if (incomingDefaults.fontFamily !== null) { defaultFontFamily = incomingDefaults.fontFamily; } - if (incomingDefaults.fontSize !== null) { - defaultFontSize = incomingDefaults.fontSize; + if (incomingDefaults.fontSizeMultiplier !== null) { + defaultFontSize = incomingDefaults.fontSizeMultiplier; } - if (incomingDefaults.lineHeight !== null) { - defaultLineHeight = incomingDefaults.lineHeight; + if (incomingDefaults.lineHeightMultiplier !== null) { + defaultLineHeight = incomingDefaults.lineHeightMultiplier; } } let colorMap = new ColorMap(_colorMap); @@ -454,8 +454,8 @@ function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[], _colorMap: colorMap.getId(rule.foreground), colorMap.getId(rule.background), rule.fontFamily, - rule.fontSize, - rule.lineHeight + rule.fontSizeMultiplier, + rule.lineHeightMultiplier ); } @@ -507,7 +507,7 @@ export class ColorMap { } } -const emptyParentScopes= Object.freeze([]); +const emptyParentScopes = Object.freeze([]); export class ThemeTrieElementRule { @@ -517,8 +517,8 @@ export class ThemeTrieElementRule { foreground: number; background: number; fontFamily: string; - fontSize: number; - lineHeight: number; + fontSizeMultiplier: number; + lineHeightMultiplier: number; constructor( scopeDepth: number, @@ -527,8 +527,8 @@ export class ThemeTrieElementRule { foreground: number, background: number, fontFamily: string, - fontSize: number, - lineHeight: number + fontSizeMultiplier: number, + lineHeightMultiplier: number ) { this.scopeDepth = scopeDepth; this.parentScopes = parentScopes || emptyParentScopes; @@ -536,8 +536,8 @@ export class ThemeTrieElementRule { this.foreground = foreground; this.background = background; this.fontFamily = fontFamily; - this.fontSize = fontSize; - this.lineHeight = lineHeight; + this.fontSizeMultiplier = fontSizeMultiplier; + this.lineHeightMultiplier = lineHeightMultiplier; } public clone(): ThemeTrieElementRule { @@ -548,8 +548,8 @@ export class ThemeTrieElementRule { this.foreground, this.background, this.fontFamily, - this.fontSize, - this.lineHeight + this.fontSizeMultiplier, + this.lineHeightMultiplier ); } @@ -567,8 +567,8 @@ export class ThemeTrieElementRule { foreground: number, background: number, fontFamily: string, - fontSize: number, - lineHeight: number + fontSizeMultiplier: number, + lineHeightMultiplier: number ): void { if (this.scopeDepth > scopeDepth) { console.log('how did this happen?'); @@ -588,11 +588,11 @@ export class ThemeTrieElementRule { if (fontFamily !== '') { this.fontFamily = fontFamily; } - if (fontSize !== 0) { - this.fontSize = fontSize; + if (fontSizeMultiplier !== 0) { + this.fontSizeMultiplier = fontSizeMultiplier; } - if (lineHeight !== 0) { - this.lineHeight = lineHeight; + if (lineHeightMultiplier !== 0) { + this.lineHeightMultiplier = lineHeightMultiplier; } } } @@ -693,11 +693,11 @@ export class ThemeTrieElement { foreground: number, background: number, fontFamily: string, - fontSize: number, - lineHeight: number, + fontSizeMultiplier: number, + lineHeightMultiplier: number, ): void { if (scope === '') { - this._doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); + this._doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); return; } @@ -720,7 +720,7 @@ export class ThemeTrieElement { this._children[head] = child; } - child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); + child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); } private _doInsertHere( @@ -730,13 +730,13 @@ export class ThemeTrieElement { foreground: number, background: number, fontFamily: string, - fontSize: number, - lineHeight: number + fontSizeMultiplier: number, + lineHeightMultiplier: number ): void { if (parentScopes === null) { // Merge into the main rule - this._mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); + this._mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); return; } @@ -746,7 +746,7 @@ export class ThemeTrieElement { if (strArrCmp(rule.parentScopes, parentScopes) === 0) { // bingo! => we get to merge this into an existing one - rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); + rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); return; } } @@ -766,11 +766,11 @@ export class ThemeTrieElement { if (fontFamily === '') { fontFamily = this._mainRule.fontFamily; } - if (fontSize === 0) { - fontSize = this._mainRule.fontSize; + if (fontSizeMultiplier === 0) { + fontSizeMultiplier = this._mainRule.fontSizeMultiplier; } - if (lineHeight === 0) { - lineHeight = this._mainRule.lineHeight; + if (lineHeightMultiplier === 0) { + lineHeightMultiplier = this._mainRule.lineHeightMultiplier; } this._rulesWithParentScopes.push(new ThemeTrieElementRule( @@ -780,8 +780,8 @@ export class ThemeTrieElement { foreground, background, fontFamily, - fontSize, - lineHeight + fontSizeMultiplier, + lineHeightMultiplier )); } } From 3b8f817d2950cfcc6c8a7103b155ebd8b1392efe Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:43:04 +0100 Subject: [PATCH 5/7] Revert "fixing the tests" This reverts commit 5cfbabd26fc8a336561a0c540e9c70e8510f6e03. --- src/tests/grammar.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index dcc0d35..6a6d676 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -163,7 +163,7 @@ test('Fonts are correctly set', async function () { ] }); const result = grammar.tokenizeLine2('bar hello', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 3)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 1.3)]); } finally { registry.dispose(); } @@ -190,7 +190,7 @@ test('Fonts are correctly set 2', async function () { ] }); const result = grammar.tokenizeLine2('function g() {}', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.3, 3)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.2, 1.3)]); } finally { registry.dispose(); } From 24614f8c696ab9211d09761d63fd4b6749fc59f9 Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:43:51 +0100 Subject: [PATCH 6/7] Revert "renaming to multiplier" This reverts commit 9db25495a5905b86dde6267eb63018cd90a6ac78. --- src/grammar/grammar.ts | 12 ++--- src/main.ts | 4 +- src/tests/grammar.test.ts | 8 ++-- src/theme.ts | 98 +++++++++++++++++++-------------------- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/grammar/grammar.ts b/src/grammar/grammar.ts index 59851fd..e152a73 100644 --- a/src/grammar/grammar.ts +++ b/src/grammar/grammar.ts @@ -1124,14 +1124,14 @@ export class FontInfo implements IFontInfo { public startIndex: number, public endIndex: number, public fontFamily: string | null, - public fontSizeMultiplier: number | null, - public lineHeightMultiplier: number | null + public fontSize: number | null, + public lineHeight: number | null ) { } optionsEqual(other: IFontInfo): boolean { return this.fontFamily === other.fontFamily - && this.fontSizeMultiplier === other.fontSizeMultiplier - && this.lineHeightMultiplier === other.lineHeightMultiplier; + && this.fontSize === other.fontSize + && this.lineHeight === other.lineHeight; } } @@ -1157,8 +1157,8 @@ export class LineFonts { return; } const fontFamily = styleAttributes.fontFamily; - const fontSize = styleAttributes.fontSizeMultiplier; - const lineHeight = styleAttributes.lineHeightMultiplier; + const fontSize = styleAttributes.fontSize; + const lineHeight = styleAttributes.lineHeight; if (!fontFamily && !fontSize && !lineHeight) { this._lastIndex = endIndex; return; diff --git a/src/main.ts b/src/main.ts index c8f2c3a..6d27764 100644 --- a/src/main.ts +++ b/src/main.ts @@ -273,12 +273,12 @@ export interface IFontInfo { /** * Font size specification */ - readonly fontSizeMultiplier: number | null; + readonly fontSize: number | null; /** * Line height specification */ - readonly lineHeightMultiplier: number | null; + readonly lineHeight: number | null; } export interface IToken { diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index 6a6d676..c67898f 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -150,8 +150,8 @@ test('Fonts are correctly set', async function () { scope: 'bar.test', settings: { fontFamily: 'monospace', - fontSizeMultiplier: 1.2, - lineHeightMultiplier: 3 + fontSize: 1.2, + lineHeight: 3 } }] }); @@ -177,8 +177,8 @@ test('Fonts are correctly set 2', async function () { scope: 'entity.name.function.ts', settings: { fontFamily: 'Times New Roman', - fontSizeMultiplier: 1.3, - lineHeightMultiplier: 3 + fontSize: 1.3, + lineHeight: 3 } }] }); diff --git a/src/theme.ts b/src/theme.ts index 57693fa..037ff0e 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -27,7 +27,7 @@ export class Theme { private readonly _colorMap: ColorMap, private readonly _defaults: StyleAttributes, private readonly _root: ThemeTrieElement - ) { } + ) {} public getColorMap(): string[] { return this._colorMap.getColorMap(); @@ -56,8 +56,8 @@ export class Theme { effectiveRule.foreground, effectiveRule.background, effectiveRule.fontFamily, - effectiveRule.fontSizeMultiplier, - effectiveRule.lineHeightMultiplier + effectiveRule.fontSize, + effectiveRule.lineHeight ); } } @@ -99,8 +99,8 @@ export interface IRawThemeSetting { readonly foreground?: string; readonly background?: string; readonly fontFamily?: string; - readonly fontSizeMultiplier?: number; - readonly lineHeightMultiplier?: number; + readonly fontSize?: number; + readonly lineHeight?: number; }; } @@ -125,7 +125,7 @@ export class ScopeStack { constructor( public readonly parent: ScopeStack | null, public readonly scopeName: ScopeName - ) { } + ) {} public push(scopeName: ScopeName): ScopeStack { return new ScopeStack(this, scopeName); @@ -219,8 +219,8 @@ export class StyleAttributes { public readonly foregroundId: number, public readonly backgroundId: number, public readonly fontFamily: string, - public readonly fontSizeMultiplier: number, - public readonly lineHeightMultiplier: number + public readonly fontSize: number, + public readonly lineHeight: number ) { } } @@ -300,13 +300,13 @@ export function parseTheme(source: IRawTheme | undefined): ParsedThemeRule[] { } let fontSize: number = 0; - if (typeof entry.settings.fontSizeMultiplier === 'number') { - fontSize = entry.settings.fontSizeMultiplier; + if (typeof entry.settings.fontSize === 'number') { + fontSize = entry.settings.fontSize; } let lineHeight: number = 0; - if (typeof entry.settings.lineHeightMultiplier === 'number') { - lineHeight = entry.settings.lineHeightMultiplier; + if (typeof entry.settings.lineHeight === 'number') { + lineHeight = entry.settings.lineHeight; } for (let j = 0, lenJ = scopes.length; j < lenJ; j++) { @@ -347,8 +347,8 @@ export class ParsedThemeRule { public readonly foreground: string | null, public readonly background: string | null, public readonly fontFamily: string, - public readonly fontSizeMultiplier: number, - public readonly lineHeightMultiplier: number, + public readonly fontSize: number, + public readonly lineHeight: number, ) { } } @@ -426,11 +426,11 @@ function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[], _colorMap: if (incomingDefaults.fontFamily !== null) { defaultFontFamily = incomingDefaults.fontFamily; } - if (incomingDefaults.fontSizeMultiplier !== null) { - defaultFontSize = incomingDefaults.fontSizeMultiplier; + if (incomingDefaults.fontSize !== null) { + defaultFontSize = incomingDefaults.fontSize; } - if (incomingDefaults.lineHeightMultiplier !== null) { - defaultLineHeight = incomingDefaults.lineHeightMultiplier; + if (incomingDefaults.lineHeight !== null) { + defaultLineHeight = incomingDefaults.lineHeight; } } let colorMap = new ColorMap(_colorMap); @@ -454,8 +454,8 @@ function resolveParsedThemeRules(parsedThemeRules: ParsedThemeRule[], _colorMap: colorMap.getId(rule.foreground), colorMap.getId(rule.background), rule.fontFamily, - rule.fontSizeMultiplier, - rule.lineHeightMultiplier + rule.fontSize, + rule.lineHeight ); } @@ -507,7 +507,7 @@ export class ColorMap { } } -const emptyParentScopes = Object.freeze([]); +const emptyParentScopes= Object.freeze([]); export class ThemeTrieElementRule { @@ -517,8 +517,8 @@ export class ThemeTrieElementRule { foreground: number; background: number; fontFamily: string; - fontSizeMultiplier: number; - lineHeightMultiplier: number; + fontSize: number; + lineHeight: number; constructor( scopeDepth: number, @@ -527,8 +527,8 @@ export class ThemeTrieElementRule { foreground: number, background: number, fontFamily: string, - fontSizeMultiplier: number, - lineHeightMultiplier: number + fontSize: number, + lineHeight: number ) { this.scopeDepth = scopeDepth; this.parentScopes = parentScopes || emptyParentScopes; @@ -536,8 +536,8 @@ export class ThemeTrieElementRule { this.foreground = foreground; this.background = background; this.fontFamily = fontFamily; - this.fontSizeMultiplier = fontSizeMultiplier; - this.lineHeightMultiplier = lineHeightMultiplier; + this.fontSize = fontSize; + this.lineHeight = lineHeight; } public clone(): ThemeTrieElementRule { @@ -548,8 +548,8 @@ export class ThemeTrieElementRule { this.foreground, this.background, this.fontFamily, - this.fontSizeMultiplier, - this.lineHeightMultiplier + this.fontSize, + this.lineHeight ); } @@ -567,8 +567,8 @@ export class ThemeTrieElementRule { foreground: number, background: number, fontFamily: string, - fontSizeMultiplier: number, - lineHeightMultiplier: number + fontSize: number, + lineHeight: number ): void { if (this.scopeDepth > scopeDepth) { console.log('how did this happen?'); @@ -588,11 +588,11 @@ export class ThemeTrieElementRule { if (fontFamily !== '') { this.fontFamily = fontFamily; } - if (fontSizeMultiplier !== 0) { - this.fontSizeMultiplier = fontSizeMultiplier; + if (fontSize !== 0) { + this.fontSize = fontSize; } - if (lineHeightMultiplier !== 0) { - this.lineHeightMultiplier = lineHeightMultiplier; + if (lineHeight !== 0) { + this.lineHeight = lineHeight; } } } @@ -693,11 +693,11 @@ export class ThemeTrieElement { foreground: number, background: number, fontFamily: string, - fontSizeMultiplier: number, - lineHeightMultiplier: number, + fontSize: number, + lineHeight: number, ): void { if (scope === '') { - this._doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); + this._doInsertHere(scopeDepth, parentScopes, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); return; } @@ -720,7 +720,7 @@ export class ThemeTrieElement { this._children[head] = child; } - child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); + child.insert(scopeDepth + 1, tail, parentScopes, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); } private _doInsertHere( @@ -730,13 +730,13 @@ export class ThemeTrieElement { foreground: number, background: number, fontFamily: string, - fontSizeMultiplier: number, - lineHeightMultiplier: number + fontSize: number, + lineHeight: number ): void { if (parentScopes === null) { // Merge into the main rule - this._mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); + this._mainRule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); return; } @@ -746,7 +746,7 @@ export class ThemeTrieElement { if (strArrCmp(rule.parentScopes, parentScopes) === 0) { // bingo! => we get to merge this into an existing one - rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSizeMultiplier, lineHeightMultiplier); + rule.acceptOverwrite(scopeDepth, fontStyle, foreground, background, fontFamily, fontSize, lineHeight); return; } } @@ -766,11 +766,11 @@ export class ThemeTrieElement { if (fontFamily === '') { fontFamily = this._mainRule.fontFamily; } - if (fontSizeMultiplier === 0) { - fontSizeMultiplier = this._mainRule.fontSizeMultiplier; + if (fontSize === 0) { + fontSize = this._mainRule.fontSize; } - if (lineHeightMultiplier === 0) { - lineHeightMultiplier = this._mainRule.lineHeightMultiplier; + if (lineHeight === 0) { + lineHeight = this._mainRule.lineHeight; } this._rulesWithParentScopes.push(new ThemeTrieElementRule( @@ -780,8 +780,8 @@ export class ThemeTrieElement { foreground, background, fontFamily, - fontSizeMultiplier, - lineHeightMultiplier + fontSize, + lineHeight )); } } From b0c710013d2df0fc0ff2e2909ba4cb451634384b Mon Sep 17 00:00:00 2001 From: Aiday Marlen Kyzy Date: Mon, 5 Jan 2026 22:44:43 +0100 Subject: [PATCH 7/7] fixing tests --- src/tests/grammar.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/grammar.test.ts b/src/tests/grammar.test.ts index c67898f..8cda262 100644 --- a/src/tests/grammar.test.ts +++ b/src/tests/grammar.test.ts @@ -163,7 +163,7 @@ test('Fonts are correctly set', async function () { ] }); const result = grammar.tokenizeLine2('bar hello', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 1.3)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(0, 3, "monospace", 1.2, 3)]); } finally { registry.dispose(); } @@ -190,7 +190,7 @@ test('Fonts are correctly set 2', async function () { ] }); const result = grammar.tokenizeLine2('function g() {}', null, undefined); - assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.2, 1.3)]); + assert.deepStrictEqual(result.fonts, [new FontInfo(9, 10, 'Times New Roman', 1.3, 3)]); } finally { registry.dispose(); }