feat: improve terminal font settings with weight control and keyboard navigation (#228)

This commit is contained in:
Yax Patel
2026-03-30 20:47:21 -07:00
committed by GitHub
parent 831b65fe65
commit c6481d8b64
10 changed files with 210 additions and 11 deletions
+7 -1
View File
@@ -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')
})
@@ -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
@@ -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<HTMLInputElement | null>(null)
const rootRef = useRef<HTMLDivElement | null>(null)
const optionRefs = useRef(new Map<string, HTMLButtonElement>())
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 (
<div ref={rootRef} className="relative max-w-sm">
<div className="relative">
<Input
ref={inputRef}
value={query}
onChange={(e) => {
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
}
/>
<div className="absolute inset-y-0 right-2 flex items-center gap-1">
{query ? (
<button
type="button"
onMouseDown={(e) => e.preventDefault()}
onClick={() => {
setQuery('')
onChange('')
setOpen(true)
focusInput()
}}
className="rounded-sm p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
aria-label="Clear font selection"
@@ -289,7 +368,14 @@ export function FontAutocomplete({
) : null}
<button
type="button"
onClick={() => setOpen((current) => !current)}
onMouseDown={(e) => e.preventDefault()}
onClick={() => {
const nextOpen = !open
setOpen(nextOpen)
if (nextOpen) {
focusInput()
}
}}
className="rounded-sm p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
aria-label="Toggle font suggestions"
title="Fonts"
@@ -301,17 +387,30 @@ export function FontAutocomplete({
{open ? (
<div className="absolute top-full z-20 mt-2 w-full overflow-hidden rounded-md border border-border/50 bg-popover shadow-md">
<ScrollArea className="max-h-64">
<div className="p-1">
<ScrollArea className={filteredSuggestions.length > 8 ? 'h-64' : undefined}>
<div id={listboxId} role="listbox" className="p-1">
{filteredSuggestions.length > 0 ? (
filteredSuggestions.map((font) => (
filteredSuggestions.map((font, index) => (
<button
key={font}
type="button"
id={`${listboxId}-option-${index}`}
role="option"
aria-selected={index === highlightedIndex}
ref={(element) => {
if (element) {
optionRefs.current.set(font, element)
return
}
optionRefs.current.delete(font)
}}
onMouseDown={(e) => e.preventDefault()}
onMouseEnter={() => setHighlightedIndex(index)}
onClick={() => commitValue(font)}
className={`flex w-full items-center justify-between rounded-sm px-3 py-2 text-left text-sm transition-colors ${
font === value ? 'bg-accent text-accent-foreground' : 'hover:bg-muted/60'
index === highlightedIndex
? 'bg-accent text-accent-foreground'
: 'hover:bg-muted/60'
}`}
>
<span className="truncate">{font}</span>
@@ -1,5 +1,12 @@
import { useState } from 'react'
import type { GlobalSettings } from '../../../../shared/types'
import {
DEFAULT_TERMINAL_FONT_WEIGHT,
TERMINAL_FONT_WEIGHT_MAX,
TERMINAL_FONT_WEIGHT_MIN,
TERMINAL_FONT_WEIGHT_STEP,
normalizeTerminalFontWeight
} from '../../../../shared/terminal-fonts'
import { Button } from '../ui/button'
import { Input } from '../ui/input'
import { Label } from '../ui/label'
@@ -111,6 +118,22 @@ export function TerminalPane({
onChange={(value) => updateSettings({ terminalFontFamily: value })}
/>
</div>
<NumberField
label="Font Weight"
description="Controls the terminal text font weight."
value={normalizeTerminalFontWeight(settings.terminalFontWeight)}
defaultValue={DEFAULT_TERMINAL_FONT_WEIGHT}
min={TERMINAL_FONT_WEIGHT_MIN}
max={TERMINAL_FONT_WEIGHT_MAX}
step={TERMINAL_FONT_WEIGHT_STEP}
suffix="100 to 900"
onChange={(value) =>
updateSettings({
terminalFontWeight: normalizeTerminalFontWeight(value)
})
}
/>
</section>
<Separator />
@@ -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 {
@@ -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(
+2
View File
@@ -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',
+28
View File
@@ -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
})
})
})
+33
View File
@@ -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)
)
}
}
+1
View File
@@ -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