Skip to content

Commit b10002a

Browse files
committed
Viewer: Add horizontal scrolling
1 parent 223b041 commit b10002a

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

apps/desktop/src/routes/viewer/+page.svelte

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151
let viewportHeight = $state(600)
5252
let contentRef: HTMLDivElement | undefined = $state()
5353
let containerRef: HTMLDivElement | undefined = $state()
54+
let linesContainerRef: HTMLDivElement | undefined = $state()
55+
56+
// High watermark of rendered line container width, for horizontal scroll
57+
let contentWidth = $state(0)
5458
5559
// Derived: which lines are visible
5660
const visibleFrom = $derived(Math.max(0, Math.floor(scrollTop / LINE_HEIGHT) - BUFFER_LINES))
@@ -126,6 +130,22 @@
126130
}
127131
})
128132
133+
// Track horizontal content width so .scroll-spacer can create a scrollbar
134+
$effect(() => {
135+
void visibleLines
136+
const rafId = requestAnimationFrame(() => {
137+
if (linesContainerRef) {
138+
const w = linesContainerRef.scrollWidth
139+
if (w > contentWidth) {
140+
contentWidth = w
141+
}
142+
}
143+
})
144+
return () => {
145+
cancelAnimationFrame(rafId)
146+
}
147+
})
148+
129149
function scheduleFetch(from: number, to: number) {
130150
// Clear any pending fetch
131151
if (fetchDebounceTimer) {
@@ -677,8 +697,15 @@
677697
bind:this={contentRef}
678698
onscroll={handleScroll}
679699
>
680-
<div class="scroll-spacer" style="height: {estimatedTotalLines() * LINE_HEIGHT}px">
681-
<div class="lines-container" style="transform: translateY({visibleFrom * LINE_HEIGHT}px)">
700+
<div
701+
class="scroll-spacer"
702+
style="height: {estimatedTotalLines() * LINE_HEIGHT}px; min-width: {contentWidth}px"
703+
>
704+
<div
705+
class="lines-container"
706+
bind:this={linesContainerRef}
707+
style="transform: translateY({visibleFrom * LINE_HEIGHT}px)"
708+
>
682709
{#each visibleLines as { lineNumber, text } (lineNumber)}
683710
<div class="line" data-line={lineNumber}>
684711
<span class="line-number" style="width: {gutterWidth}ch" aria-hidden="true"
@@ -812,7 +839,8 @@
812839
.lines-container {
813840
position: absolute;
814841
left: 0;
815-
right: 0;
842+
width: max-content;
843+
min-width: 100%;
816844
}
817845
818846
.line {
@@ -839,10 +867,6 @@
839867
840868
.line-text {
841869
white-space: pre;
842-
word-break: break-all;
843-
flex: 1;
844-
min-width: 0;
845-
overflow: hidden;
846870
}
847871
848872
mark {

0 commit comments

Comments
 (0)