From a8efa2b1875b15b0ccd4924faf1788b00c12cce8 Mon Sep 17 00:00:00 2001 From: CyanSalt Date: Thu, 21 Mar 2024 16:50:48 +0800 Subject: [PATCH] fix: refine marker style --- src/renderer/components/TerminalTeletype.vue | 28 +++++++++++++------- src/renderer/utils/shell-integration.ts | 9 ++++--- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/renderer/components/TerminalTeletype.vue b/src/renderer/components/TerminalTeletype.vue index 79c1797a..a5c73dc7 100644 --- a/src/renderer/components/TerminalTeletype.vue +++ b/src/renderer/components/TerminalTeletype.vue @@ -58,9 +58,14 @@ function fit() { const observer = new ResizeObserver(fit) -const cell = $computed(() => { - const xterm = tab.xterm - return xterm['_core']._renderService.dimensions.css.cell +let cell = $ref<{ width: number, height: number }>() + +const variables = $computed(() => { + if (!cell) return {} + return { + '--cell-width': `${cell.width}px`, + '--cell-height': `${cell.height}px`, + } }) watchEffect((onInvalidate) => { @@ -69,9 +74,7 @@ watchEffect((onInvalidate) => { const xterm = tab.xterm if (xterm.element) return xterm.open(el) - // Add cell size properties - el.style.setProperty('--cell-width', `${cell.width}px`) - el.style.setProperty('--cell-height', `${cell.height}px`) + cell = xterm['_core']._renderService.dimensions.css.cell tab.deferred.open.resolve() xterm.focus() observer.observe(el) @@ -89,6 +92,7 @@ const renderableCompletion = $computed(() => { }) const selectedCompletion = $computed(() => { + if (!renderableCompletion) return undefined return renderableCompletion.items[renderableCompletion.index] }) @@ -111,7 +115,7 @@ function getCompletionIcon(item: CommandCompletion) { } function selectCompletion(event: MouseEvent, item: CommandCompletion) { - const index = renderableCompletion.items + const index = renderableCompletion!.items .findIndex(completion => completion.value === item.value) if (index === -1) return if (isMatchLinkModifier(event)) { @@ -127,8 +131,8 @@ onBeforeUpdate(() => { }) function mountCompletion(el: HTMLElement, item: CommandCompletion) { - if (!renderableCompletion.mounted.has(item.value)) { - renderableCompletion.mounted.set(item.value, el) + if (!renderableCompletion!.mounted.has(item.value)) { + renderableCompletion!.mounted.set(item.value, el) } } @@ -148,7 +152,7 @@ function mountCompletion(el: HTMLElement, item: CommandCompletion) { > 0 ? theme.red : theme.green, - shouldHighlight ? 'transparent' : 'strong', + shouldHighlight ? 'stroked' : 'strong', currentCommand, ) } @@ -364,7 +364,7 @@ export class ShellIntegrationAddon implements ITerminalAddon { xterm: Terminal, marker: IMarker, color: string, - style?: 'strong' | 'transparent' | undefined, + style?: 'strong' | 'stroked' | undefined, command?: IntegratedShellCommand, ) { const rgba = toRGBA(color) @@ -377,8 +377,11 @@ export class ShellIntegrationAddon implements ITerminalAddon { })! updateDecorationElement(decoration, el => { el.style.setProperty('--color', `${rgba.r} ${rgba.g} ${rgba.b}`) - el.style.setProperty('--opacity', style === 'strong' ? '1' : (style === 'transparent' ? '0' : '0.25')) + el.style.setProperty('--opacity', style ? '1' : '0.25') el.classList.add('terminal-command-mark') + if (style === 'stroked') { + el.classList.add('is-stroked') + } if (command) { el.classList.add('is-interactive') el.addEventListener('click', event => {