Skip to content

Commit da6f15a

Browse files
committed
fix: wrap lines and compute width
1 parent 9e8c805 commit da6f15a

File tree

2 files changed

+82
-56
lines changed

2 files changed

+82
-56
lines changed

app/components/Code/Viewer.vue

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ watch(
8686
</script>
8787

8888
<template>
89-
<div class="code-viewer flex min-h-full max-w-full">
89+
<div class="code-viewer flex min-h-full max-w-full" :style="{ '--line-digits': lineDigits }">
9090
<!-- Line numbers column -->
9191
<div
9292
class="line-numbers shrink-0 bg-bg-subtle border-ie border-solid border-border text-end select-none relative"
93-
:style="{ '--line-digits': lineDigits }"
9493
aria-hidden="true"
9594
>
9695
<!-- This needs to be a native <a> element, because `LinkBase` (or specifically `NuxtLink`) does not seem to work when trying to prevent default behavior (jumping to the anchor) -->
@@ -113,9 +112,9 @@ watch(
113112
</div>
114113

115114
<!-- Code content -->
116-
<div class="code-content flex-1 overflow-x-auto min-w-0">
115+
<div class="code-content">
117116
<!-- eslint-disable vue/no-v-html -- HTML is generated server-side by Shiki -->
118-
<div ref="codeRef" class="code-lines min-w-full w-fit" v-html="html" />
117+
<div ref="codeRef" class="code-lines" v-html="html" />
119118
<!-- eslint-enable vue/no-v-html -->
120119
</div>
121120
</div>
@@ -124,59 +123,69 @@ watch(
124123
<style scoped>
125124
.code-viewer {
126125
font-size: 14px;
127-
}
128-
129-
.line-numbers {
130126
/* 1ch per digit + 1.5rem (px-3 * 2) padding */
131-
min-width: calc(var(--line-digits) * 1ch + 1.5rem);
132-
}
133-
134-
.code-content :deep(pre) {
135-
margin: 0;
136-
padding: 0;
137-
background: transparent !important;
138-
overflow: visible;
139-
}
140-
141-
.code-content :deep(code) {
142-
display: block;
143-
padding: 0 1rem;
144-
background: transparent !important;
145-
}
146-
147-
.code-content :deep(.line) {
148-
display: block;
149-
/* Ensure consistent height matching line numbers */
150-
line-height: 24px;
151-
min-height: 24px;
152-
max-height: 24px;
153-
white-space: pre;
154-
overflow: hidden;
155-
transition: background-color 0.1s;
127+
--line-numbers-width: calc(var(--line-digits) * 1ch + 1.5rem);
156128
}
157129
158-
/* Highlighted lines in code content - extend full width with negative margin */
159-
.code-content :deep(.line.highlighted) {
160-
@apply bg-yellow-500/20;
161-
margin: 0 -1rem;
162-
padding: 0 1rem;
163-
}
164-
165-
/* Clickable import links */
166-
.code-content :deep(.import-link) {
167-
color: inherit;
168-
text-decoration: underline;
169-
text-decoration-style: dotted;
170-
text-decoration-color: rgba(158, 203, 255, 0.5); /* syntax.str with transparency */
171-
text-underline-offset: 2px;
172-
transition:
173-
text-decoration-color 0.15s,
174-
text-decoration-style 0.15s;
175-
cursor: pointer;
130+
.line-numbers {
131+
min-width: var(--line-numbers-width);
176132
}
177133
178-
.code-content :deep(.import-link:hover) {
179-
text-decoration-style: solid;
180-
text-decoration-color: #9ecbff; /* syntax.str - light blue */
134+
.code-content {
135+
flex: 1;
136+
min-width: 0;
137+
max-width: calc(100% - var(--line-numbers-width));
138+
139+
&:deep(pre) {
140+
margin: 0;
141+
padding: 0;
142+
background: transparent !important;
143+
overflow: visible;
144+
max-width: 100%;
145+
}
146+
147+
&:deep(code) {
148+
display: block;
149+
padding: 0 1rem;
150+
background: transparent !important;
151+
max-width: 100%;
152+
}
153+
154+
&:deep(.line) {
155+
display: flex;
156+
flex-wrap: wrap;
157+
/* Ensure consistent height matching line numbers */
158+
line-height: 24px;
159+
min-height: 24px;
160+
white-space: pre-wrap;
161+
overflow: hidden;
162+
transition: background-color 0.1s;
163+
max-width: 100%;
164+
}
165+
166+
/* Highlighted lines in code content - extend full width with negative margin */
167+
&:deep(.line.highlighted) {
168+
@apply bg-yellow-500/20;
169+
margin: 0 -1rem;
170+
padding: 0 1rem;
171+
}
172+
173+
/* Clickable import links */
174+
&:deep(.import-link) {
175+
color: inherit;
176+
text-decoration: underline;
177+
text-decoration-style: dotted;
178+
text-decoration-color: rgba(158, 203, 255, 0.5); /* syntax.str with transparency */
179+
text-underline-offset: 2px;
180+
transition:
181+
text-decoration-color 0.15s,
182+
text-decoration-style 0.15s;
183+
cursor: pointer;
184+
}
185+
186+
&:deep(.import-link:hover) {
187+
text-decoration-style: solid;
188+
text-decoration-color: #9ecbff; /* syntax.str - light blue */
189+
}
181190
}
182191
</style>

app/pages/package-code/[[org]]/[packageName]/v/[version]/[...filePath].vue

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ defineOgImageComponent('Default', {
347347
</div>
348348

349349
<!-- Main content: file tree + file viewer -->
350-
<div v-else-if="fileTree" class="flex flex-1" dir="ltr">
350+
<div v-else-if="fileTree" class="main-content flex flex-1" dir="ltr">
351351
<!-- File tree sidebar - sticky with internal scroll -->
352352
<aside
353-
class="w-64 lg:w-72 border-ie border-border shrink-0 hidden md:block bg-bg-subtle sticky top-25 self-start h-[calc(100vh-7rem)] overflow-y-auto"
353+
class="file-tree border-ie border-border shrink-0 hidden md:block bg-bg-subtle sticky top-25 self-start h-[calc(100vh-7rem)] overflow-y-auto"
354354
>
355355
<CodeFileTree
356356
:tree="fileTree.tree"
@@ -361,7 +361,7 @@ defineOgImageComponent('Default', {
361361
</aside>
362362

363363
<!-- File content / Directory listing - sticky with internal scroll on desktop -->
364-
<div class="flex-1 min-w-0 self-start">
364+
<div class="file-viewer flex-1 min-w-0 self-start">
365365
<div
366366
class="sticky z-10 top-25 bg-bg border-b border-border px-4 py-2 flex items-center justify-between gap-2 text-nowrap overflow-x-auto max-w-full"
367367
>
@@ -584,3 +584,20 @@ defineOgImageComponent('Default', {
584584
</ClientOnly>
585585
</main>
586586
</template>
587+
588+
<style scoped>
589+
.main-content {
590+
--sidebar-space: calc(var(--spacing) * 64);
591+
@screen lg {
592+
--sidebar-space: calc(var(--spacing) * 72);
593+
}
594+
595+
.file-tree {
596+
width: var(--sidebar-space);
597+
}
598+
599+
.file-viewer {
600+
width: calc(100vw - var(--sidebar-space));
601+
}
602+
}
603+
</style>

0 commit comments

Comments
 (0)