Skip to content
Open
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
22 changes: 22 additions & 0 deletions src/main/ghostty/mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ describe('mapGhosttyToOrca — font & cursor', () => {
expect(result.unsupportedKeys).toEqual([])
})

it('maps repeated font families to a primary font and ordered fallbacks', () => {
const result = mapGhosttyToOrca({
'font-family': ['MesloLGS NF', 'Microsoft YaHei UI', 'Noto Sans Arabic']
})
expect(result.diff).toEqual({
terminalFontFamily: 'MesloLGS NF',
terminalFontFallbacks: ['Microsoft YaHei UI', 'Noto Sans Arabic']
})
expect(result.unsupportedKeys).toEqual([])
})

it('keeps valid repeated font families when the final entry is blank', () => {
const result = mapGhosttyToOrca({
'font-family': ['JetBrains Mono', '']
})
expect(result.diff).toEqual({
terminalFontFamily: 'JetBrains Mono',
terminalFontFallbacks: []
})
expect(result.unsupportedKeys).toEqual([])
})

it('skips invalid font-size values', () => {
const result = mapGhosttyToOrca({ 'font-size': 'not-a-number' })
expect(result.diff).toEqual({})
Expand Down
16 changes: 12 additions & 4 deletions src/main/ghostty/mapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GhosttyImportPreview, GlobalSettings } from '../../shared/global-settings-types'
import type { TerminalColorOverrides } from '../../shared/terminal-color-overrides'
import { HEX_COLOR_RE } from '../../shared/color-validation'
import { normalizeTerminalFontFallbacks } from '../../shared/terminal-font-fallbacks'
import { parsePaddingValue, parseStrictInt } from './numeric-config-values'

const PALETTE_INDEX_MAP: Record<number, keyof TerminalColorOverrides> = {
Expand Down Expand Up @@ -211,11 +212,18 @@ export function mapGhosttyToOrca(
return { key: 'terminalCursorOpacity', value: num }
},

'font-family': (v) => {
if (typeof v !== 'string' || v.trim().length === 0) {
'font-family': (v, rawValue) => {
const families = normalizeTerminalFontFallbacks(Array.isArray(rawValue) ? rawValue : [v])
const primary = families[0]
if (!primary) {
return null
}
return { key: 'terminalFontFamily', value: v }
return Array.isArray(rawValue)
? [
{ key: 'terminalFontFamily', value: primary },
{ key: 'terminalFontFallbacks', value: families.slice(1) }
]
: { key: 'terminalFontFamily', value: primary }
},

'font-size': (v) => {
Expand Down Expand Up @@ -286,7 +294,7 @@ export function mapGhosttyToOrca(
continue
}

if (!value.trim()) {
if (!value.trim() && (key !== 'font-family' || !Array.isArray(rawValue))) {
unsupportedKeys.push(key)
continue
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/ipc/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,33 @@ describe('registerSettingsHandlers', () => {
)
})

it('normalizes terminal fallback font stacks before persistence', async () => {
store.getSettings.mockReturnValue({ terminalFontFallbacks: [] })
store.updateSettings.mockReturnValue({
terminalFontFallbacks: ['Microsoft YaHei UI', 'Noto Sans Arabic']
})
registerSettingsHandlers(store as never)

const handler = handleMock.mock.calls.find((call) => call[0] === 'settings:set')?.[1] as (
_event: unknown,
args: unknown
) => Promise<unknown>

await handler(settingsInvokeEvent, {
terminalFontFallbacks: [
' Microsoft YaHei UI ',
null,
'Noto Sans Arabic',
'microsoft yahei ui'
]
})

expect(store.updateSettings).toHaveBeenCalledWith(
{ terminalFontFallbacks: ['Microsoft YaHei UI', 'Noto Sans Arabic'] },
{ notifyListeners: true, originWebContentsId: 1 }
)
})

it('normalizes custom terminal themes from renderer settings IPC', async () => {
store.getSettings.mockReturnValue({ terminalCustomThemes: [] })
store.updateSettings.mockReturnValue({ terminalCustomThemes: [] })
Expand Down
4 changes: 4 additions & 0 deletions src/main/ipc/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { normalizeAppIconId } from '../../shared/app-icon'
import { normalizeUiLanguage } from '../../shared/ui-language'
import { applyAppIcon } from '../app-icon'
import { normalizeTerminalCustomThemes } from '../../shared/terminal-custom-themes'
import { normalizeTerminalFontFallbacks } from '../../shared/terminal-font-fallbacks'
import { normalizeDesktopTerminalScrollbackRows } from '../../shared/terminal-scrollback-policy'
import { normalizeTerminalLineHeight } from '../../shared/terminal-line-height-settings'
import { prepareLocalWorktreeRootsForRepos } from '../worktree-root-preparation'
Expand Down Expand Up @@ -56,6 +57,9 @@ function sanitizeRendererSettingsUpdate(args: Partial<GlobalSettings>): Partial<
// writes must pass the dedicated reviewed-fingerprint handlers.
delete sanitizedArgs.pluginConsents
delete sanitizedArgs.disabledPlugins
if ('terminalFontFallbacks' in args) {
sanitizedArgs.terminalFontFallbacks = normalizeTerminalFontFallbacks(args.terminalFontFallbacks)
}
return sanitizedArgs
}

Expand Down
25 changes: 25 additions & 0 deletions src/main/persistence-settings-ui-defaults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('Store', () => {
expect(settings.editorAutoSave).toBe(false)
expect(settings.editorAutoSaveDelayMs).toBe(1000)
expect(settings.terminalFontSize).toBe(14)
expect(settings.terminalFontFallbacks).toEqual([])
expect(settings.terminalFontWeight).toBe(500)
expect(settings.terminalFontWeightBold).toBe(700)
expect(settings.terminalScrollSensitivity).toBe(1.15)
Expand Down Expand Up @@ -121,6 +122,30 @@ describe('Store', () => {
expect((readDataFile() as PersistedState).settings.terminalLineHeight).toBe(1)
})

it('normalizes persisted terminal fallback font stacks on load', async () => {
const persisted = getDefaultPersistedState(testState.dir)
writeDataFile({
...persisted,
settings: {
...persisted.settings,
terminalFontFallbacks: [
' Microsoft YaHei UI ',
'',
42,
'Noto Sans Arabic',
'microsoft yahei ui'
]
}
})

const store = await createStore()

expect(store.getSettings().terminalFontFallbacks).toEqual([
'Microsoft YaHei UI',
'Noto Sans Arabic'
])
})

it('returns default UI state when no data file exists', async () => {
const store = await createStore()
const ui = store.getUI()
Expand Down
6 changes: 6 additions & 0 deletions src/main/persistence/applying-settings/settings-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../../shared/tui-agent-launch-defaults'
import { normalizeTerminalQuickCommands } from '../../../shared/terminal-quick-commands'
import { normalizeTerminalCustomThemes } from '../../../shared/terminal-custom-themes'
import { normalizeTerminalFontFallbacks } from '../../../shared/terminal-font-fallbacks'
import { normalizeTerminalCursorStyleDefault } from '../../../shared/terminal-cursor-style-settings'
import { normalizeDesktopTerminalScrollbackRows } from '../../../shared/terminal-scrollback-policy'
import { normalizeTerminalMinimumContrastRatio } from '../../../shared/terminal-minimum-contrast-settings'
Expand Down Expand Up @@ -123,6 +124,11 @@ export function updateSettings(
)
)
}
if ('terminalFontFallbacks' in updates) {
sanitizedUpdates.terminalFontFallbacks = normalizeTerminalFontFallbacks(
updates.terminalFontFallbacks
)
}
if ('terminalScrollbackRows' in updates) {
sanitizedUpdates.terminalScrollbackRows = normalizeDesktopTerminalScrollbackRows(
updates.terminalScrollbackRows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { normalizeOpenInApplications } from '../../../shared/open-in-application
import { normalizeTerminalShortcutPolicy } from '../../../shared/keybindings'
import { normalizeAppIconId } from '../../../shared/app-icon'
import { normalizeTerminalCustomThemes } from '../../../shared/terminal-custom-themes'
import { normalizeTerminalFontFallbacks } from '../../../shared/terminal-font-fallbacks'
import { projectSourceControlAiToLegacyCommitMessageAi } from '../../../shared/source-control-ai'
import { normalizeUiLanguage } from '../../../shared/ui-language'
import { normalizeNativeChatShellEnvironmentVariables } from '../../../shared/native-chat-shell-environment'
Expand Down Expand Up @@ -76,6 +77,7 @@ export function normalizeLoadedGlobalSettings(
primarySelectionDefaultedForTerminalDefaults || stampPrimarySelectionTerminalDefaults,
...migratedAutoRenameBranchFromWork,
...migratedTerminalCursorStyle,
terminalFontFallbacks: normalizeTerminalFontFallbacks(parsed.settings?.terminalFontFallbacks),
terminalLineHeight: migratedTerminalLineHeight,
// Why: the old true default was inherited, but false was always an explicit opt-out and must survive this one-shot reset.
terminalRightClickToPaste: terminalRightClickToPasteDefaultedForPlatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export function buildPreviewAppearanceOptions(
)
return {
fontSize: settings?.terminalFontSize ?? 14,
fontFamily: buildFontFamily(settings?.terminalFontFamily ?? ''),
fontFamily: buildFontFamily(
settings?.terminalFontFamily ?? '',
settings?.terminalFontFallbacks
),
fontWeight: fontWeights.fontWeight,
fontWeightBold: fontWeights.fontWeightBold,
cursorStyle,
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/src/components/settings/FontAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type FontAutocompleteProps = {
value: string
suggestions: string[]
onChange: (value: string) => void
onCommit?: (value: string) => void
placeholder?: string
ariaLabel?: string
onRequestSuggestions?: () => void
/** Fires with whichever option the user is currently highlighting in the
* dropdown (via mouse hover or keyboard arrow), or null when nothing is
Expand All @@ -24,7 +26,9 @@ export function FontAutocomplete({
value,
suggestions,
onChange,
onCommit,
placeholder = 'SF Mono',
ariaLabel,
onRequestSuggestions,
onPreviewFontFamily
}: FontAutocompleteProps): React.JSX.Element {
Expand Down Expand Up @@ -128,6 +132,7 @@ export function FontAutocomplete({
setQuery(nextValue)
setIsFilteringQuery(false)
onChange(nextValue)
onCommit?.(nextValue)
setOpen(false)
}

Expand Down Expand Up @@ -161,6 +166,7 @@ export function FontAutocomplete({
setIsFilteringQuery(false)
setOpen(true)
}}
onBlur={() => onCommit?.(query)}
onKeyDown={(e) => {
if (e.key === 'Escape') {
if (open) {
Expand Down Expand Up @@ -199,11 +205,20 @@ export function FontAutocomplete({
e.preventDefault()
commitValue(highlightedFont)
}
return
}

if (e.key === 'Enter' && onCommit) {
e.preventDefault()
setIsFilteringQuery(false)
onCommit(query)
setOpen(false)
}
}}
placeholder={placeholder}
className="pr-18"
role="combobox"
aria-label={ariaLabel}
aria-autocomplete="list"
aria-expanded={open}
aria-controls={listboxId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { act, useState, type ReactNode } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { FontAutocomplete } from './SettingsFormControls'
import { FontAutocomplete } from './FontAutocomplete'
import { FONT_SUGGESTION_RENDER_LIMIT } from './settings-form-option-filter'

vi.mock('@/i18n/i18n', () => ({
Expand Down Expand Up @@ -188,6 +188,34 @@ describe('FontAutocomplete', () => {
expect(getOptionLabels()).toEqual(['JetBrains Mono'])
})

it('shows all installed fonts after committing a custom value with Enter', async () => {
function Harness(): ReactNode {
const [value, setValue] = useState('Geist')
return (
<FontAutocomplete
value={value}
suggestions={['Arial', 'Geist', 'JetBrains Mono']}
onChange={setValue}
onCommit={vi.fn()}
/>
)
}

await act(async () => root.render(<Harness />))

const input = getInput()
await act(async () => input.focus())
await typeIntoInput(input, 'Custom CJK Font')
await act(async () =>
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
)
await act(async () =>
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
)

expect(getOptionLabels()).toEqual(['Arial', 'Geist', 'JetBrains Mono'])
})

it('requests installed suggestions only after the picker is used', async () => {
const requestSuggestions = vi.fn()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Button } from '../ui/button'
import { SettingsRow, SettingsSubsectionHeader, FontAutocomplete } from './SettingsFormControls'
import { SearchableSetting } from './SearchableSetting'
import { TerminalFontSizeSetting } from './TerminalFontSizeSetting'
import { TerminalFontFallbackSetting } from './TerminalFontFallbackSetting'
import { TerminalAdvancedTypographyControls } from './TerminalAdvancedTypographyControls'
import { TerminalThemeCatalogSection } from './TerminalThemeSections'
import { TerminalWindowSection } from './TerminalWindowSection'
Expand Down Expand Up @@ -114,7 +115,7 @@ export function TerminalAppearanceSection({
const showThemeCatalog = !isSearching || themeCatalogMatches || previewAdvancedMatches
const primaryTypographyMatches = matchesSettingsSearch(
searchQuery,
terminalTypographyEntries.slice(0, 2)
terminalTypographyEntries.slice(0, 3)
)
const ghosttyImportMatches =
showDesktopThemeImports && matchesSettingsSearch(searchQuery, ghosttyImportEntries)
Expand Down Expand Up @@ -235,6 +236,39 @@ export function TerminalAppearanceSection({
}
/>
</SearchableSetting>

<SearchableSetting
title={translate(
'auto.components.settings.TerminalAppearanceSection.13b09da243',
'Fallback Fonts'
)}
description={terminalTypographyEntries[2]?.description}
keywords={
terminalTypographyEntries[2]?.keywords ?? [
'terminal',
'typography',
'font',
'fallback'
]
}
forceVisible={forceVisiblePrimary}
>
<SettingsRow
alignTop
label={translate(
'auto.components.settings.TerminalAppearanceSection.13b09da243',
'Fallback Fonts'
)}
control={
<TerminalFontFallbackSetting
value={settings.terminalFontFallbacks ?? []}
suggestions={terminalFontSuggestions}
onRequestSuggestions={onRequestFontSuggestions}
onChange={(value) => updateSettings({ terminalFontFallbacks: value })}
/>
}
/>
</SearchableSetting>
</div>

{showTypographyAdvancedDisclosure ? (
Expand Down
Loading