diff --git a/src/main/ghostty/mapper.test.ts b/src/main/ghostty/mapper.test.ts index c8076db63ffc..7e46395936a7 100644 --- a/src/main/ghostty/mapper.test.ts +++ b/src/main/ghostty/mapper.test.ts @@ -16,6 +16,41 @@ describe('mapGhosttyToOrca — font & cursor', () => { expect(result.unsupportedKeys).toEqual([]) }) + // Ghostty treats a repeated `font-family` as a fallback chain: the first entry + // is the primary face and the rest are fallbacks. The generic "last occurrence + // wins" flattening in the mapper kept the last one, i.e. the least-preferred + // face. See #15985. + it('keeps the first font-family when the key is repeated', () => { + const result = mapGhosttyToOrca({ 'font-family': ['Menlo', 'Monaco'] }) + expect(result.diff).toEqual({ terminalFontFamily: 'Menlo' }) + expect(result.unsupportedKeys).toEqual([]) + }) + + it('skips blank entries when picking the first font-family', () => { + const result = mapGhosttyToOrca({ 'font-family': [' ', 'Fira Code', 'Monaco'] }) + expect(result.diff).toEqual({ terminalFontFamily: 'Fira Code' }) + expect(result.unsupportedKeys).toEqual([]) + }) + + it('takes the first font-family after a mid-list reset, not the cleared one', () => { + // Why: an empty entry resets the list, so only what follows it is still in + // effect. Searching the whole array would import `Fira Code`, which this + // config explicitly cleared before asking for Monaco. + const result = mapGhosttyToOrca({ 'font-family': ['Fira Code', '', 'Monaco'] }) + expect(result.diff).toEqual({ terminalFontFamily: 'Monaco' }) + expect(result.unsupportedKeys).toEqual([]) + }) + + it('treats a trailing blank font-family as a cleared list, not a missing value', () => { + // Why: Ghostty documents an empty value on a repeatable key as resetting the list -- + // "specify the value as "" (empty string) to reset the list and then set the new + // values". A config ending in `font-family = ` has therefore cleared its fonts on + // purpose, so importing the earlier entry would resurrect a font the user removed. + const result = mapGhosttyToOrca({ 'font-family': ['Fira Code', ' '] }) + expect(result.diff).toEqual({}) + expect(result.unsupportedKeys).toEqual(['font-family']) + }) + it('skips invalid font-size values', () => { const result = mapGhosttyToOrca({ 'font-size': 'not-a-number' }) expect(result.diff).toEqual({}) diff --git a/src/main/ghostty/mapper.ts b/src/main/ghostty/mapper.ts index ad8b8d050c82..ea7f915bdb95 100644 --- a/src/main/ghostty/mapper.ts +++ b/src/main/ghostty/mapper.ts @@ -211,11 +211,28 @@ export function mapGhosttyToOrca( return { key: 'terminalCursorOpacity', value: num } }, - 'font-family': (v) => { - if (typeof v !== 'string' || v.trim().length === 0) { + // Why: Ghostty treats a repeated font-family as a fallback chain — the first + // entry is the primary face, the rest are fallbacks. The generic flattening + // above keeps the LAST occurrence, which is the right default for keys where + // a later line overrides an earlier one, but here it picks the least-preferred + // face. Read the unflattened value and take the first usable entry instead. + // + // An empty entry is not a blank to skip over: Ghostty documents it as + // resetting the list ("specify the value as \"\" to reset the list and then + // set the new values"), so only the entries after the LAST reset are still + // in effect. Searching the whole array would import a face the user cleared. + 'font-family': (v, rawValue) => { + if (!Array.isArray(rawValue)) { + return typeof v === 'string' && v.trim().length > 0 + ? { key: 'terminalFontFamily', value: v } + : null + } + const lastReset = rawValue.map((entry) => entry.trim().length === 0).lastIndexOf(true) + const first = rawValue.slice(lastReset + 1).find((entry) => entry.trim().length > 0) + if (typeof first !== 'string') { return null } - return { key: 'terminalFontFamily', value: v } + return { key: 'terminalFontFamily', value: first } }, 'font-size': (v) => {