diff --git a/src/main/persistence.test.ts b/src/main/persistence.test.ts index 38d8e99f3..17c7a32b1 100644 --- a/src/main/persistence.test.ts +++ b/src/main/persistence.test.ts @@ -68,6 +68,7 @@ describe('Store', () => { expect(settings.branchPrefix).toBe('git-username') expect(settings.theme).toBe('system') expect(settings.terminalFontSize).toBe(14) + expect(settings.terminalFontWeight).toBe(500) expect(settings.rightSidebarOpenByDefault).toBe(true) }) @@ -233,9 +234,14 @@ describe('Store', () => { const initial = store.getSettings() expect(initial.theme).toBe('system') - const updated = store.updateSettings({ theme: 'dark', terminalFontSize: 16 }) + const updated = store.updateSettings({ + theme: 'dark', + terminalFontSize: 16, + terminalFontWeight: 600 + }) expect(updated.theme).toBe('dark') expect(updated.terminalFontSize).toBe(16) + expect(updated.terminalFontWeight).toBe(600) // Other fields preserved expect(updated.branchPrefix).toBe('git-username') }) diff --git a/src/renderer/src/components/settings/SettingsConstants.ts b/src/renderer/src/components/settings/SettingsConstants.ts index b10fb63ff..17254f8b0 100644 --- a/src/renderer/src/components/settings/SettingsConstants.ts +++ b/src/renderer/src/components/settings/SettingsConstants.ts @@ -4,7 +4,6 @@ import { getDefaultRepoHookSettings } from '../../../../shared/constants' export type HookName = keyof OrcaHooks['scripts'] export const DEFAULT_REPO_HOOK_SETTINGS = getDefaultRepoHookSettings() export const MAX_THEME_RESULTS = 80 -export const MAX_FONT_RESULTS = 12 export const SCROLLBACK_PRESETS_MB = [10, 25, 50, 100, 250] as const export const ZOOM_STEP = 0.5 export const ZOOM_MIN = -3 diff --git a/src/renderer/src/components/settings/SettingsFormControls.tsx b/src/renderer/src/components/settings/SettingsFormControls.tsx index a74437b2d..dbed096e4 100644 --- a/src/renderer/src/components/settings/SettingsFormControls.tsx +++ b/src/renderer/src/components/settings/SettingsFormControls.tsx @@ -1,10 +1,10 @@ -import { useEffect, useState, useMemo, useRef } from 'react' +import { useEffect, useId, useMemo, useRef, useState } from 'react' import { ScrollArea } from '../ui/scroll-area' import { Input } from '../ui/input' import { Label } from '../ui/label' import { Check, ChevronsUpDown, CircleX } from 'lucide-react' import { BUILTIN_TERMINAL_THEME_NAMES, normalizeColor } from '@/lib/terminal-theme' -import { MAX_THEME_RESULTS, MAX_FONT_RESULTS } from './SettingsConstants' +import { MAX_THEME_RESULTS } from './SettingsConstants' type ThemePickerProps = { label: string @@ -216,7 +216,11 @@ export function FontAutocomplete({ const [query, setQuery] = useState(value) const [prevValue, setPrevValue] = useState(value) const [open, setOpen] = useState(false) + const [highlightedIndex, setHighlightedIndex] = useState(-1) + const inputRef = useRef(null) const rootRef = useRef(null) + const optionRefs = useRef(new Map()) + const listboxId = useId() if (value !== prevValue) { setPrevValue(value) @@ -246,20 +250,47 @@ export function FontAutocomplete({ !font.toLowerCase().startsWith(normalizedQuery) && font.toLowerCase().includes(normalizedQuery) ) - const ordered = normalizedQuery ? [...startsWith, ...includes] : suggestions - return ordered.slice(0, MAX_FONT_RESULTS) + return normalizedQuery ? [...startsWith, ...includes] : suggestions }, [suggestions, normalizedQuery]) + useEffect(() => { + if (!open || filteredSuggestions.length === 0) { + setHighlightedIndex(-1) + return + } + + const selectedIndex = filteredSuggestions.findIndex((font) => font === value) + setHighlightedIndex(Math.max(selectedIndex, 0)) + }, [filteredSuggestions, open, value]) + + useEffect(() => { + if (!open || highlightedIndex < 0) { + return + } + + const highlightedFont = filteredSuggestions[highlightedIndex] + if (!highlightedFont) { + return + } + + optionRefs.current.get(highlightedFont)?.scrollIntoView({ block: 'nearest' }) + }, [filteredSuggestions, highlightedIndex, open]) + const commitValue = (nextValue: string): void => { setQuery(nextValue) onChange(nextValue) setOpen(false) } + const focusInput = (): void => { + inputRef.current?.focus() + } + return (
{ const next = e.target.value @@ -268,17 +299,65 @@ export function FontAutocomplete({ setOpen(true) }} onFocus={() => setOpen(true)} + onKeyDown={(e) => { + if (e.key === 'Escape') { + if (open) { + e.preventDefault() + setOpen(false) + } + return + } + + if (e.key === 'ArrowDown') { + e.preventDefault() + setOpen(true) + if (filteredSuggestions.length > 0) { + setHighlightedIndex((current) => + current < 0 ? 0 : Math.min(current + 1, filteredSuggestions.length - 1) + ) + } + return + } + + if (e.key === 'ArrowUp') { + e.preventDefault() + setOpen(true) + if (filteredSuggestions.length > 0) { + setHighlightedIndex((current) => + current < 0 ? filteredSuggestions.length - 1 : Math.max(current - 1, 0) + ) + } + return + } + + if (e.key === 'Enter' && open && highlightedIndex >= 0) { + const highlightedFont = filteredSuggestions[highlightedIndex] + if (highlightedFont) { + e.preventDefault() + commitValue(highlightedFont) + } + } + }} placeholder="SF Mono" className="pr-18" + role="combobox" + aria-autocomplete="list" + aria-expanded={open} + aria-controls={listboxId} + aria-activedescendant={ + open && highlightedIndex >= 0 ? `${listboxId}-option-${highlightedIndex}` : undefined + } />
{query ? (
+ + + updateSettings({ + terminalFontWeight: normalizeTerminalFontWeight(value) + }) + } + /> diff --git a/src/renderer/src/components/terminal-pane/terminal-appearance.ts b/src/renderer/src/components/terminal-pane/terminal-appearance.ts index a5ae9c047..529747a25 100644 --- a/src/renderer/src/components/terminal-pane/terminal-appearance.ts +++ b/src/renderer/src/components/terminal-pane/terminal-appearance.ts @@ -1,6 +1,7 @@ import type { ITheme } from '@xterm/xterm' import type { PaneManager } from '@/lib/pane-manager/pane-manager' import type { GlobalSettings } from '../../../../shared/types' +import { resolveTerminalFontWeights } from '../../../../shared/terminal-fonts' import { getBuiltinTheme, resolvePaneStyleOptions, @@ -20,6 +21,7 @@ export function applyTerminalAppearance( const paneStyles = resolvePaneStyleOptions(settings) const theme: ITheme | null = appearance.theme ?? getBuiltinTheme(appearance.themeName) const paneBackground = theme?.background ?? '#000000' + const terminalFontWeights = resolveTerminalFontWeights(settings.terminalFontWeight) for (const pane of manager.getPanes()) { if (theme) { @@ -30,6 +32,8 @@ export function applyTerminalAppearance( const paneSize = paneFontSizes.get(pane.id) pane.terminal.options.fontSize = paneSize ?? settings.terminalFontSize pane.terminal.options.fontFamily = buildFontFamily(settings.terminalFontFamily) + pane.terminal.options.fontWeight = terminalFontWeights.fontWeight + pane.terminal.options.fontWeightBold = terminalFontWeights.fontWeightBold try { pane.fitAddon.fit() } catch { diff --git a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts index ee3397eaa..798217833 100644 --- a/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts +++ b/src/renderer/src/components/terminal-pane/use-terminal-pane-lifecycle.ts @@ -5,6 +5,7 @@ import { useAppStore } from '@/store' import { createFilePathLinkProvider, handleOscLink } from './terminal-link-handlers' import type { LinkHandlerDeps } from './terminal-link-handlers' import type { GlobalSettings, TerminalLayoutSnapshot } from '../../../../shared/types' +import { resolveTerminalFontWeights } from '../../../../shared/terminal-fonts' import { buildFontFamily, replayTerminalLayout } from './layout-serialization' import { applyExpandedLayoutTo, restoreExpandedLayoutFrom } from './expand-collapse' import { applyTerminalAppearance } from './terminal-appearance' @@ -197,9 +198,12 @@ export function useTerminalPaneLifecycle({ }, terminalOptions: () => { const currentSettings = settingsRef.current + const terminalFontWeights = resolveTerminalFontWeights(currentSettings?.terminalFontWeight) return { fontSize: currentSettings?.terminalFontSize ?? 14, fontFamily: buildFontFamily(currentSettings?.terminalFontFamily ?? 'SF Mono'), + fontWeight: terminalFontWeights.fontWeight, + fontWeightBold: terminalFontWeights.fontWeightBold, scrollback: Math.min( 50_000, Math.max( diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 0a1c752d0..525c42fb5 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -5,6 +5,7 @@ import type { RepoHookSettings, WorkspaceSessionState } from './types' +import { DEFAULT_TERMINAL_FONT_WEIGHT } from './terminal-fonts' export const SCHEMA_VERSION = 1 @@ -28,6 +29,7 @@ export function getDefaultSettings(homedir: string): GlobalSettings { theme: 'system', terminalFontSize: 14, terminalFontFamily: 'SF Mono', + terminalFontWeight: DEFAULT_TERMINAL_FONT_WEIGHT, terminalCursorStyle: 'bar', terminalCursorBlink: true, terminalThemeDark: 'Ghostty Default Style Dark', diff --git a/src/shared/terminal-fonts.test.ts b/src/shared/terminal-fonts.test.ts new file mode 100644 index 000000000..ab71db1c4 --- /dev/null +++ b/src/shared/terminal-fonts.test.ts @@ -0,0 +1,28 @@ +import { describe, expect, it } from 'vitest' +import { + DEFAULT_TERMINAL_FONT_WEIGHT, + resolveTerminalFontWeights, + normalizeTerminalFontWeight +} from './terminal-fonts' + +describe('terminal font weights', () => { + it('falls back to the Orca default when the value is missing', () => { + expect(normalizeTerminalFontWeight(undefined)).toBe(DEFAULT_TERMINAL_FONT_WEIGHT) + }) + + it('clamps weights to the supported xterm range', () => { + expect(normalizeTerminalFontWeight(10)).toBe(100) + expect(normalizeTerminalFontWeight(1200)).toBe(900) + }) + + it('keeps bold text heavier than the base terminal weight', () => { + expect(resolveTerminalFontWeights(500)).toEqual({ + fontWeight: 500, + fontWeightBold: 700 + }) + expect(resolveTerminalFontWeights(800)).toEqual({ + fontWeight: 800, + fontWeightBold: 900 + }) + }) +}) diff --git a/src/shared/terminal-fonts.ts b/src/shared/terminal-fonts.ts new file mode 100644 index 000000000..445edbeb1 --- /dev/null +++ b/src/shared/terminal-fonts.ts @@ -0,0 +1,33 @@ +export const DEFAULT_TERMINAL_FONT_WEIGHT = 500 +export const TERMINAL_FONT_WEIGHT_MIN = 100 +export const TERMINAL_FONT_WEIGHT_MAX = 900 +export const TERMINAL_FONT_WEIGHT_STEP = 100 +export const DEFAULT_TERMINAL_FONT_WEIGHT_BOLD = 700 + +export function normalizeTerminalFontWeight(fontWeight: number | null | undefined): number { + const numericFontWeight = typeof fontWeight === 'number' ? fontWeight : NaN + + if (!Number.isFinite(numericFontWeight)) { + return DEFAULT_TERMINAL_FONT_WEIGHT + } + + return Math.min( + TERMINAL_FONT_WEIGHT_MAX, + Math.max(TERMINAL_FONT_WEIGHT_MIN, Math.round(numericFontWeight)) + ) +} + +export function resolveTerminalFontWeights(fontWeight: number | null | undefined): { + fontWeight: number + fontWeightBold: number +} { + const normalizedFontWeight = normalizeTerminalFontWeight(fontWeight) + + return { + fontWeight: normalizedFontWeight, + fontWeightBold: Math.min( + TERMINAL_FONT_WEIGHT_MAX, + Math.max(DEFAULT_TERMINAL_FONT_WEIGHT_BOLD, normalizedFontWeight + 200) + ) + } +} diff --git a/src/shared/types.ts b/src/shared/types.ts index 0df91770f..667b0da9e 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -170,6 +170,7 @@ export type GlobalSettings = { theme: 'system' | 'dark' | 'light' terminalFontSize: number terminalFontFamily: string + terminalFontWeight: number terminalCursorStyle: 'bar' | 'block' | 'underline' terminalCursorBlink: boolean terminalThemeDark: string