Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ vi.mock('@xterm/xterm', () => ({
}
}))

vi.mock('@xterm/addon-ligatures', () => ({
LigaturesAddon: class LigaturesAddon {
vi.mock('@/lib/pane-manager/terminal-ligatures-addon', () => ({
TerminalLigaturesAddon: class TerminalLigaturesAddon {
dispose: Mock

constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { Terminal } from '@xterm/xterm'
import { LigaturesAddon } from '@xterm/addon-ligatures'
import { TerminalLigaturesAddon } from '@/lib/pane-manager/terminal-ligatures-addon'
import { Moon, Sun } from 'lucide-react'
import '@xterm/xterm/css/xterm.css'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
Expand Down Expand Up @@ -60,7 +60,7 @@ export function TerminalSettingsPreview({
}: TerminalSettingsPreviewProps): React.JSX.Element {
const containerRef = useRef<HTMLDivElement | null>(null)
const terminalRef = useRef<Terminal | null>(null)
const ligaturesAddonRef = useRef<LigaturesAddon | null>(null)
const ligaturesAddonRef = useRef<TerminalLigaturesAddon | null>(null)
const skipInitialOptionMutationRef = useRef(false)
const skipInitialThemeRewriteRef = useRef(false)

Expand Down Expand Up @@ -228,7 +228,7 @@ export function TerminalSettingsPreview({
const enabled = resolveTerminalLigaturesEnabled(settings.terminalLigatures, effectiveFontFamily)
const current = ligaturesAddonRef.current
if (enabled && !current) {
const addon = new LigaturesAddon()
const addon = new TerminalLigaturesAddon()
try {
terminal.loadAddon(addon)
ligaturesAddonRef.current = addon
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { Terminal } from '@xterm/xterm'
import { TerminalLigaturesAddon } from './terminal-ligatures-addon'

describe('TerminalLigaturesAddon font access', () => {
afterEach(() => {
vi.unstubAllGlobals()
})

it('joins common ligatures without reading installed font files', async () => {
const queryLocalFonts = vi.fn(async () => [])
vi.stubGlobal('window', { queryLocalFonts })
let joiner: ((text: string) => [number, number][]) | null = null
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this fixture provides every Terminal member the addon touches.
const terminal = {
element: { style: {} },
options: { fontFamily: '"Commit Mono", monospace' },
rows: 24,
refresh: vi.fn(),
registerCharacterJoiner(registered: (text: string) => [number, number][]): number {
joiner = registered
return 1
},
deregisterCharacterJoiner: vi.fn()
} as unknown as Terminal
new TerminalLigaturesAddon().activate(terminal)

const ranges = joiner!('a => b')
await Promise.resolve()

expect(ranges).toEqual([[2, 4]])
expect(queryLocalFonts).not.toHaveBeenCalled()
})
})
10 changes: 10 additions & 0 deletions src/renderer/src/lib/pane-manager/terminal-ligatures-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,18 @@ function createCachedCharacterJoiner(
export class TerminalLigaturesAddon extends LigaturesAddon {
override activate(terminal: Terminal): void {
const cache = new LigatureRangeCache()
// Without a font family upstream never reads font files (whole-file parse per terminal OOMed renderers) and joins its common-ligature list, as before 1.4.247.
const optionsWithoutFontFamily = new Proxy(terminal.options, {
get(options, key) {
// oxlint-disable-next-line anti-slop/no-reflect-get -- Proxy get trap default forward.
return key === 'fontFamily' ? undefined : Reflect.get(options, key, options)
}
})
const terminalForAddon = new Proxy(terminal, {
get(target, property) {
if (property === 'options') {
return optionsWithoutFontFamily
}
if (property === 'registerCharacterJoiner') {
return (joiner: CharacterJoiner): number =>
target.registerCharacterJoiner(createCachedCharacterJoiner(target, joiner, cache))
Expand Down
Loading