Skip to content
Merged
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
27 changes: 20 additions & 7 deletions src/features/version-control/git/components/inline-git-blame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const InlineGitBlame = ({ blameLine, className }: InlineGitBlameProps) =>
const triggerRef = useRef<HTMLDivElement>(null);
const popoverRef = useRef<HTMLDivElement>(null);
const hideTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const showTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const documentRef = useRef(document);
const { settings } = useSettingsStore();
const [isCopied, setIsCopied] = useState(false);
Expand All @@ -41,6 +42,13 @@ export const InlineGitBlame = ({ blameLine, className }: InlineGitBlameProps) =>
}
}, []);

const clearShowTimeout = useCallback(() => {
if (showTimeoutRef.current) {
clearTimeout(showTimeoutRef.current);
showTimeoutRef.current = null;
}
}, []);

const scheduleHide = useCallback(() => {
clearHideTimeout();
hideTimeoutRef.current = setTimeout(() => {
Expand Down Expand Up @@ -81,17 +89,21 @@ export const InlineGitBlame = ({ blameLine, className }: InlineGitBlameProps) =>

const showPopover = useCallback(() => {
clearHideTimeout();
if (!showCard) {
updatePosition();
setShowCard(true);
showOverlay("git-blame");
if (!showCard && !showTimeoutRef.current) {
showTimeoutRef.current = setTimeout(() => {
updatePosition();
setShowCard(true);
showOverlay("git-blame");
showTimeoutRef.current = null;
}, 1000);
}
}, [clearHideTimeout, showCard, updatePosition, showOverlay]);

const hidePopover = useCallback(() => {
clearShowTimeout();
scheduleHide();
hideOverlay("git-blame");
}, [scheduleHide, hideOverlay]);
}, [clearShowTimeout, scheduleHide, hideOverlay]);

const handleCopyCommitHash = useCallback(
async (e: React.MouseEvent) => {
Expand Down Expand Up @@ -244,12 +256,13 @@ export const InlineGitBlame = ({ blameLine, className }: InlineGitBlameProps) =>
};
}, [showCard]);

// Clean up timeout on unmount
// Clean up timeouts on unmount
useEffect(() => {
return () => {
clearHideTimeout();
clearShowTimeout();
};
}, [clearHideTimeout]);
}, [clearHideTimeout, clearShowTimeout]);

return (
<div ref={triggerRef} className="relative inline-flex">
Expand Down