fix: restore default terminal font when setting is empty

This commit is contained in:
purocean
2026-09-19 12:01:11 +08:00
parent 397c2386c7
commit 40cc29da86
2 changed files with 8 additions and 4 deletions
+6 -2
View File
@@ -29,6 +29,7 @@ export default defineComponent({
const domRef = ref<HTMLElement | null>(null)
let xterm: Terminal | null = null
let defaultFontFamily: string | undefined
// eslint-disable-next-line no-undef
let socket: Socket | null = null
let resizeObserver: ResizeObserver | null = null
@@ -72,7 +73,7 @@ export default defineComponent({
return {
fontSize: getSetting('terminal.font-size', 16),
fontFamily: fontFamily || undefined,
fontFamily: fontFamily || defaultFontFamily,
}
}
@@ -100,14 +101,17 @@ export default defineComponent({
}
if (!xterm) {
const { fontFamily, ...terminalOptions } = getTerminalOptions()
xterm = new Terminal({
cols: 80,
rows: 24,
cursorStyle: 'underline',
fontWeightBold: '500',
...getTerminalOptions(),
...terminalOptions,
...opts
})
defaultFontFamily = xterm.options.fontFamily
xterm.options.fontFamily = opts?.fontFamily || fontFamily || defaultFontFamily
changeTheme()
+2 -2
View File
@@ -36,7 +36,7 @@ const mocks = vi.hoisted(() => ({
dispose = vi.fn()
constructor (options: any) {
this.options = options
this.options = { fontFamily: 'courier-new, courier, monospace', ...options }
mocks.terminals.push(this)
}
},
@@ -221,7 +221,7 @@ describe('Xterm', () => {
mocks.settings.set('terminal.font-family', '')
mocks.settingHandler({ changedKeys: ['terminal.font-size'] })
expect(term.options.fontSize).toBe(20)
expect(term.options.fontFamily).toBeUndefined()
expect(term.options.fontFamily).toBe('courier-new, courier, monospace')
expect(mocks.fitAddons[0].fit).toHaveBeenCalledTimes(3)
socket.handlers.get('disconnect')?.()