agent-ecosystem/src/renderer/hooks/useContinuousScrollNav.ts
iliya 0df816bba6 feat: enhance diff view with continuous scroll and lazy loading
- Introduced a continuous scroll mode for the diff view, allowing users to review multiple files in a single scrollable container.
- Added lazy loading functionality to improve performance by loading file content as it approaches the viewport.
- Implemented a new portion collapse feature to allow users to expand unchanged regions incrementally, enhancing context retention during reviews.
- Updated navigation to support smooth scrolling between files and improved keyboard shortcuts for file navigation.
- Enhanced the review toolbar to manage actions across all files, including bulk accept/reject options.
- Added new hooks and components to support the continuous scroll and lazy loading features, ensuring a seamless user experience.
2026-02-25 15:39:14 +02:00

50 lines
1.3 KiB
TypeScript

import { type RefObject, useCallback, useRef } from 'react';
import { waitForScrollEnd } from '@renderer/hooks/navigation/utils';
interface UseContinuousScrollNavOptions {
scrollContainerRef: RefObject<HTMLElement | null>;
}
interface UseContinuousScrollNavReturn {
scrollToFile: (filePath: string) => void;
isProgrammaticScroll: RefObject<boolean>;
}
export function useContinuousScrollNav(
options: UseContinuousScrollNavOptions
): UseContinuousScrollNavReturn {
const { scrollContainerRef } = options;
const isProgrammaticScroll = useRef(false);
const scrollGeneration = useRef(0);
const scrollToFile = useCallback(
(filePath: string) => {
const container = scrollContainerRef.current;
if (!container) return;
const section = container.querySelector<HTMLElement>(
`[data-file-path="${CSS.escape(filePath)}"]`
);
if (!section) return;
const gen = ++scrollGeneration.current;
isProgrammaticScroll.current = true;
section.scrollIntoView({ behavior: 'smooth', block: 'start' });
void waitForScrollEnd(container, 500).then(() => {
if (scrollGeneration.current === gen) {
isProgrammaticScroll.current = false;
}
});
},
[scrollContainerRef]
);
return {
scrollToFile,
isProgrammaticScroll,
};
}