Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/main/ghostty/mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})

it('skips invalid font-size values', () => {
const result = mapGhosttyToOrca({ 'font-size': 'not-a-number' })
expect(result.diff).toEqual({})
Expand Down
23 changes: 20 additions & 3 deletions src/main/ghostty/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Comment on lines +224 to +235

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Allow trailing blank entries to reach the font-family parser.

When rawValue is ['Fira Code', ' '], the loop uses the last entry as value. Line 295 then marks the key unsupported before this parser runs. The valid primary font is lost. Skip the generic blank check for font-family; this parser already returns null when all entries are blank. Add a regression test for a trailing blank entry.

Proposed fix
-    if (!value.trim()) {
+    if (key !== 'font-family' && !value.trim()) {
       unsupportedKeys.push(key)
       continue
     }

},

'font-size': (v) => {
Expand Down