Skip to content

Commit b98c28b

Browse files
committed
refactor: use css variable for line width calc
1 parent d95b297 commit b98c28b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

app/components/Code/Viewer.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ const lineNumbers = computed(() => {
1616
return Array.from({ length: props.lines }, (_, i) => i + 1)
1717
})
1818
19-
// Dynamically compute line number column width based on digit count
20-
const lineNumberWidth = computed(() => {
21-
const digits = String(props.lines).length
22-
// ch unit matches monospace digit width + 1.5rem for px-3 padding
23-
return `calc(${digits}ch + 1.5rem)`
19+
// Used for CSS calculation of line number column width
20+
const lineDigits = computed(() => {
21+
return String(props.lines).length
2422
})
2523
2624
// Check if a line is selected
@@ -66,7 +64,7 @@ watch(
6664
<!-- Line numbers column -->
6765
<div
6866
class="line-numbers shrink-0 bg-bg-subtle border-ie border-solid border-border text-end select-none relative"
69-
:style="{ minWidth: lineNumberWidth }"
67+
:style="{ '--line-digits': lineDigits }"
7068
aria-hidden="true"
7169
>
7270
<a
@@ -101,6 +99,11 @@ watch(
10199
font-size: 14px;
102100
}
103101
102+
.line-numbers {
103+
/* 1ch per digit + 1.5rem (px-3 * 2) padding */
104+
min-width: calc(var(--line-digits) * 1ch + 1.5rem);
105+
}
106+
104107
.code-content :deep(pre) {
105108
margin: 0;
106109
padding: 0;

0 commit comments

Comments
 (0)