Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions apps/app/src/components/secondary-panel/FilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -534,17 +534,23 @@ export function FilePreview({
state.textPreviewKind === "csv" &&
bodyViewMode === "preview";
const usesFullHeightLayout =
usesIframeLayout || usesCsvPreviewLayout || usesCodeLayout;
const usesContentHeightLayout = usesMarkdownPreviewLayout;
usesIframeLayout ||
usesCsvPreviewLayout ||
usesCodeLayout ||
usesMarkdownPreviewLayout;

return (
<div
className={
usesFullHeightLayout
? "@container/page flex h-full min-h-0 flex-col"
: usesContentHeightLayout
? "@container/page flex min-h-full flex-col"
: "@container/page min-h-full"
? cn(
"@container/page flex h-full min-h-0 flex-col",
usesMarkdownPreviewLayout && "overflow-y-auto",
)
: "@container/page min-h-full"
}
data-file-preview-scroll-container={
usesMarkdownPreviewLayout ? "" : undefined
}
style={FILE_PREVIEW_WRAPPER_STYLE}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ const noop = () => {};
function Harness({
panelStateId,
browserOnly = false,
contentFillsRegion = false,
}: {
panelStateId?: string;
browserOnly?: boolean;
contentFillsRegion?: boolean;
}) {
const documents = ["reading.md", "short.md"].map((path) =>
createWorkspaceFilePreviewFixedPanelTab({
Expand All @@ -75,6 +77,7 @@ function Harness({
)
.map((document) => ({
tab: document,
contentFillsRegion,
label: document.path,
leadingVisual: null,
statusLabel: null,
Expand Down Expand Up @@ -166,9 +169,10 @@ function renderHarness(props: Parameters<typeof Harness>[0] = {}) {
}

function scrollContainer() {
const container = document.querySelector<HTMLDivElement>(
const containers = document.querySelectorAll<HTMLDivElement>(
"[data-file-preview-scroll-container]",
);
const container = containers[containers.length - 1];
if (!container) throw new Error("Missing file scroll container");
return container;
}
Expand Down Expand Up @@ -205,6 +209,18 @@ afterEach(() => {
});

describe("Markdown reading position in open secondary-panel tabs", () => {
it("provides a bounded scroll container inside a full-height file opener", () => {
renderHarness({ contentFillsRegion: true });
const container = scrollContainer();
expect(container.classList.contains("overflow-y-auto")).toBe(true);
expect(container.classList.contains("h-full")).toBe(true);
expect(container.classList.contains("min-h-0")).toBe(true);
scrollTo(780);
selectTab("short.md");
selectTab("reading.md");
expect(scrollContainer().scrollTop).toBe(780);
});

it.each(["different tabs", "shared tab ids", "panel remount"])(
"restores the originating thread after %s",
(transition) => {
Expand Down
Loading