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
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ function ScrollToFile({
const scrollContainer = v.getScrollContainerElement();
if (!scrollContainer) return;

const target = scrollContainer.querySelector(
const entry = scrollContainer.querySelector(
`[data-diff-path="${CSS.escape(path)}"]`,
);
if (!target) return;
) as HTMLElement | null;
const header = scrollContainer.querySelector(
`[data-diff-entry-header-path="${CSS.escape(path)}"]`,
) as HTMLElement | null;
if (!entry || !header) return;

const offset = v.getOffsetInScrollContainer(target as HTMLElement);
const offset = v.getOffsetInScrollContainer(header);
scrollContainer.scrollTo({ top: offset });
lastScrolledPath.current = path;
if (focusTick != null) lastFocusTick.current = focusTick;
Expand All @@ -54,7 +57,7 @@ function ScrollToFile({
// few frames so the annotation slot has time to render.
let attempts = 0;
const tryScroll = () => {
const lineEl = findLineElement(target as HTMLElement, focusLine);
const lineEl = findLineElement(entry, focusLine);
if (lineEl) {
lineEl.scrollIntoView({ block: "center" });
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ export const DiffFileEntry = memo(function DiffFileEntry({
}

const shouldMount = reason ? showFullDiff : hasBeenNearRef.current;
const header = (
<DiffFileHeader
path={file.path}
status={file.status}
additions={file.additions}
deletions={file.deletions}
expandUnchanged={expandUnchanged}
onToggleExpandUnchanged={handleToggleExpandUnchanged}
collapsed={collapsed}
onToggleCollapsed={handleToggleCollapsed}
viewed={viewed}
onToggleViewed={handleToggleViewed}
onOpenFile={handleOpenFile}
onOpenInExternalEditor={handleOpenInExternalEditor}
onDiscard={requestDiscard}
/>
);

return (
<div
Expand All @@ -193,24 +210,15 @@ export const DiffFileEntry = memo(function DiffFileEntry({
minHeight: collapsed ? COLLAPSED_HEIGHT_PX : expandedHeight(file),
}}
>
{header}
{shouldMount ? (
<WorkspaceDiff
workspaceId={workspaceId}
path={file.path}
status={file.status}
source={file.source}
additions={file.additions}
deletions={file.deletions}
diffStyle={diffStyle}
expandUnchanged={expandUnchanged}
onToggleExpandUnchanged={handleToggleExpandUnchanged}
collapsed={collapsed}
onToggleCollapsed={handleToggleCollapsed}
viewed={viewed}
onToggleViewed={handleToggleViewed}
onOpenFile={handleOpenFile}
onOpenInExternalEditor={handleOpenInExternalEditor}
onDiscard={requestDiscard}
focusLine={focusLine}
focusTick={focusTick}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export function DiffFileHeader({
const name = lastSlash >= 0 ? path.slice(lastSlash + 1) : path;

return (
<div className="group/diff-file-header @container/diff-file-header sticky top-0 z-10 flex min-w-0 flex-nowrap items-center gap-1 bg-card px-3 py-2">
<div
data-diff-entry-header-path={path}
className="group/diff-file-header @container/diff-file-header sticky top-0 z-10 flex min-w-0 flex-nowrap items-center gap-1 bg-card px-3 py-2"
>
<button
type="button"
onClick={onToggleCollapsed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
import { useResolvedTheme, useTerminalTheme } from "renderer/stores/theme";
import type { DiffFileSource } from "../../../../../useChangeset";
import { CommentThread } from "../CommentThread";
import { DiffFileHeader } from "../DiffFileHeader";
import {
type DiffCommentThread,
useDiffAnnotations,
Expand All @@ -19,41 +18,21 @@ import {
interface WorkspaceDiffProps {
workspaceId: string;
path: string;
status: string;
source: DiffFileSource;
additions: number;
deletions: number;
diffStyle: "split" | "unified";
expandUnchanged: boolean;
onToggleExpandUnchanged: () => void;
collapsed: boolean;
onToggleCollapsed: () => void;
viewed: boolean;
onToggleViewed: () => void;
onOpenFile?: (openInNewTab?: boolean) => void;
onOpenInExternalEditor?: () => void;
onDiscard?: () => void;
focusLine?: number;
focusTick?: number;
}

export const WorkspaceDiff = memo(function WorkspaceDiff({
workspaceId,
path,
status,
source,
additions,
deletions,
diffStyle,
expandUnchanged,
onToggleExpandUnchanged,
collapsed,
onToggleCollapsed,
viewed,
onToggleViewed,
onOpenFile,
onOpenInExternalEditor,
onDiscard,
focusLine,
focusTick,
}: WorkspaceDiffProps) {
Expand Down Expand Up @@ -132,21 +111,6 @@ export const WorkspaceDiff = memo(function WorkspaceDiff({

return (
<div className="flex flex-col">
<DiffFileHeader
path={path}
status={status}
additions={additions}
deletions={deletions}
expandUnchanged={expandUnchanged}
onToggleExpandUnchanged={onToggleExpandUnchanged}
collapsed={collapsed}
onToggleCollapsed={onToggleCollapsed}
viewed={viewed}
onToggleViewed={onToggleViewed}
onOpenFile={onOpenFile}
onOpenInExternalEditor={onOpenInExternalEditor}
onDiscard={onDiscard}
/>
{diffQuery.data ? (
<MultiFileDiff<DiffCommentThread>
oldFile={diffQuery.data.oldFile}
Expand Down
Loading