From e5dc4e3ffc0bc9e9423ffff63d7d5896092a8b9e Mon Sep 17 00:00:00 2001 From: linonetwo Date: Sat, 13 Dec 2025 14:11:19 +0800 Subject: [PATCH] feat: Auto-select the first file if none is selected --- src/windows/GitLog/CommitDetailsPanel.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/windows/GitLog/CommitDetailsPanel.tsx b/src/windows/GitLog/CommitDetailsPanel.tsx index 9de7dc18..1844d20d 100644 --- a/src/windows/GitLog/CommitDetailsPanel.tsx +++ b/src/windows/GitLog/CommitDetailsPanel.tsx @@ -10,7 +10,7 @@ import { styled } from '@mui/material/styles'; import Tab from '@mui/material/Tab'; import Tabs from '@mui/material/Tabs'; import Typography from '@mui/material/Typography'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { getFileStatusStyles, type GitFileStatus } from './fileStatusStyles'; @@ -85,6 +85,13 @@ export function CommitDetailsPanel( // Use files from commit entry (already loaded in useGitLogData) const fileChanges = commit?.files ?? []; + // Auto-select the first file if none is selected + useEffect(() => { + if (fileChanges.length > 0 && !selectedFile && onFileSelect) { + onFileSelect(fileChanges[0].path); + } + }, [commit, fileChanges, selectedFile, onFileSelect]); + const handleRevert = async () => { if (!commit || isReverting) return; @@ -141,7 +148,7 @@ export function CommitDetailsPanel( const handleCopyHash = () => { if (!commit) return; - navigator.clipboard.writeText(commit.hash); + void navigator.clipboard.writeText(commit.hash); }; const handleOpenInGitHub = async () => {