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
37 changes: 33 additions & 4 deletions apps/staged/src/lib/features/diff/DiffModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@
let mobileDiffStartY = 0;
let mobileDiffStartDragX = 0;
let mobileDiffIsDragging = $state(false);
let mobileDiffIsScrolling = false;
let mobileDiffLastY = 0;
let diffViewerScrollApi: { scrollBy: (side: 'before' | 'after', deltaY: number) => void } | null =
$state(null);
let mobileDiffStyle = $derived(
`--mobile-diff-drag-x: ${mobileDiffDragX}px;` +
`--mobile-diff-rest-offset: ${MOBILE_DIFF_REST_OFFSET}px;` +
Expand Down Expand Up @@ -1010,6 +1014,7 @@
function resetMobileDiffDrag() {
mobileDiffPointerId = null;
mobileDiffIsDragging = false;
mobileDiffIsScrolling = false;
mobileDiffDragX = 0;
}

Expand All @@ -1030,20 +1035,43 @@
mobileDiffPointerId = event.pointerId;
mobileDiffStartX = event.clientX;
mobileDiffStartY = event.clientY;
mobileDiffLastY = event.clientY;
mobileDiffStartDragX = mobileDiffDragX;
mobileDiffIsDragging = false;
diffViewerContainerEl?.setPointerCapture(event.pointerId);
mobileDiffIsScrolling = false;
}

function handleMobileDiffPointerMove(event: PointerEvent) {
if (!isSmallDiffViewport || mobileDiffPointerId !== event.pointerId) return;

const deltaX = event.clientX - mobileDiffStartX;
const deltaY = event.clientY - mobileDiffStartY;

// Already in vertical scroll mode — translate touch delta to scroll
if (mobileDiffIsScrolling) {
event.preventDefault();
const moveDeltaY = event.clientY - mobileDiffLastY;
mobileDiffLastY = event.clientY;
diffViewerScrollApi?.scrollBy('after', -moveDeltaY);
return;
}

if (!mobileDiffIsDragging) {
const horizontalIntent = Math.abs(deltaX) > 8 && Math.abs(deltaX) > Math.abs(deltaY);
if (!horizontalIntent) return;
mobileDiffIsDragging = true;
// Determine gesture direction once past dead zone
if (Math.abs(deltaX) > 8 && Math.abs(deltaX) > Math.abs(deltaY)) {
// Horizontal intent — capture pointer and start drag
mobileDiffIsDragging = true;
diffViewerContainerEl?.setPointerCapture(event.pointerId);
} else if (Math.abs(deltaY) > 8 && Math.abs(deltaY) > Math.abs(deltaX)) {
// Vertical intent — start scroll mode
mobileDiffIsScrolling = true;
mobileDiffLastY = event.clientY;
event.preventDefault();
diffViewerScrollApi?.scrollBy('after', -deltaY);
Comment on lines +1069 to +1070
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve mobile scrolling for markdown preview

When a Markdown diff is toggled to preview mode on a small viewport, the preview panes scroll via native overflow-y: auto on .code-area.markdown-mode, not via scrollController. This vertical branch now calls preventDefault() and only updates diffViewerScrollApi.scrollBy('after', ...), so a touch swipe that enters this mode can suppress the native preview scroll while changing an off-screen code-mode scroll position instead. Gate this path out for markdown preview or expose an API that scrolls the active markdown container.

Useful? React with 👍 / 👎.

return;
} else {
return;
}
}

event.preventDefault();
Expand Down Expand Up @@ -1273,6 +1301,7 @@
onCommentCommit={readonly ? undefined : handleNewCommit}
onCommentGithub={readonly || !hasPr ? undefined : handleSendToGithub}
commentGithubState={readonly || !hasPr ? undefined : getCommentGithubState}
bind:scrollApi={diffViewerScrollApi}
/>
</div>

Expand Down
9 changes: 9 additions & 0 deletions packages/diff-viewer/src/lib/components/DiffViewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@
onCommentGithub?: (comment: Comment) => void;
/** Returns the GitHub button state for a given comment. */
commentGithubState?: (comment: Comment) => GithubButtonState;

/** Bindable API object exposing scroll control for external callers (e.g. mobile touch scroll). */
scrollApi?: { scrollBy: (side: 'before' | 'after', deltaY: number) => void } | null;
}

let {
Expand All @@ -142,6 +145,7 @@
onCommentCommit,
onCommentGithub,
commentGithubState,
scrollApi = $bindable(null),
}: Props = $props();

// ==========================================================================
Expand Down Expand Up @@ -359,6 +363,11 @@

const scrollController = createScrollController();

// Expose scroll API for external callers (e.g. mobile touch scroll in DiffModal)
scrollApi = {
scrollBy: (side, deltaY) => scrollController.scrollBy(side, deltaY),
};

// Update scroll controller with active alignments
$effect(() => {
const filePath = diff ? getFilePath(diff) : null;
Expand Down