Skip to content

Commit b797fca

Browse files
authored
fix: public viewer markdown scroll and source editor position retention (#231)
Public viewer: change overflow:hidden to overflow:auto on .content container so markdown and other non-iframe content can scroll. Source editor: keep SourceEditor mounted (hidden via CSS) when switching to Preview mode, preserving CodeMirror scroll position, cursor, and undo history across tab switches.
1 parent ae9df50 commit b797fca

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

pkg/portal/templates/public_viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
flex: 1;
168168
display: flex;
169169
flex-direction: column;
170-
overflow: hidden;
170+
overflow: auto;
171171
}
172172
.content > div {
173173
flex: 1;

ui/src/components/AssetViewer.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,22 @@ export function AssetViewer({
254254
)}
255255

256256
{content !== undefined ? (
257-
viewMode === "source" && canEditSource ? (
258-
<Suspense fallback={<LoadingIndicator />}>
259-
<SourceEditor
260-
content={editedContent}
261-
contentType={asset.content_type}
262-
onChange={(v) => { setEditedContent(v); setDirty(true); }}
263-
/>
264-
</Suspense>
265-
) : (
266-
<ContentRenderer contentType={asset.content_type} content={hasChanges ? editedContent : (content as string)} />
267-
)
257+
<>
258+
{canEditSource && (
259+
<div style={{ display: viewMode === "source" ? undefined : "none" }}>
260+
<Suspense fallback={<LoadingIndicator />}>
261+
<SourceEditor
262+
content={editedContent}
263+
contentType={asset.content_type}
264+
onChange={(v) => { setEditedContent(v); setDirty(true); }}
265+
/>
266+
</Suspense>
267+
</div>
268+
)}
269+
{(viewMode !== "source" || !canEditSource) && (
270+
<ContentRenderer contentType={asset.content_type} content={hasChanges ? editedContent : (content as string)} />
271+
)}
272+
</>
268273
) : (
269274
<LoadingIndicator />
270275
)}

0 commit comments

Comments
 (0)