From bb148f4106c7a9633f142996c2ac98f5f2692ffd Mon Sep 17 00:00:00 2001 From: YoVinchen Date: Wed, 13 Aug 2025 00:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=A1=B9=E7=9B=AE=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-tauri/src/commands/git.rs | 25 ++++++ src/components/FileExplorerPanelEnhanced.tsx | 51 ------------ src/components/GitPanelEnhanced.tsx | 82 ++++++++------------ 3 files changed, 57 insertions(+), 101 deletions(-) diff --git a/src-tauri/src/commands/git.rs b/src-tauri/src/commands/git.rs index 4ead458..4b0212e 100644 --- a/src-tauri/src/commands/git.rs +++ b/src-tauri/src/commands/git.rs @@ -430,4 +430,29 @@ pub async fn get_git_diff( pub async fn get_git_commits(project_path: String, limit: usize) -> Result, String> { // 使用已有的 get_git_history 函数,直接传递 limit 参数 get_git_history(project_path, Some(limit), None).await +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse_git_status() { + let status_text = "?? test-untracked.txt\nA staged-file.txt\n M modified-file.txt"; + let (staged, modified, untracked, conflicted) = parse_git_status(status_text); + + println!("Untracked files: {:?}", untracked); + println!("Staged files: {:?}", staged); + println!("Modified files: {:?}", modified); + + assert_eq!(untracked.len(), 1); + assert_eq!(untracked[0].path, "test-untracked.txt"); + assert_eq!(untracked[0].status, "untracked"); + + assert_eq!(staged.len(), 1); + assert_eq!(staged[0].path, "staged-file.txt"); + + assert_eq!(modified.len(), 1); + assert_eq!(modified[0].path, "modified-file.txt"); + } } \ No newline at end of file diff --git a/src/components/FileExplorerPanelEnhanced.tsx b/src/components/FileExplorerPanelEnhanced.tsx index 42b4be1..3343726 100644 --- a/src/components/FileExplorerPanelEnhanced.tsx +++ b/src/components/FileExplorerPanelEnhanced.tsx @@ -1,5 +1,4 @@ import React, { useState, useEffect, useCallback, useRef } from "react"; -import { motion, AnimatePresence } from "framer-motion"; import { invoke } from "@tauri-apps/api/core"; import { listen, type UnlistenFn } from "@tauri-apps/api/event"; import { @@ -17,7 +16,6 @@ import { RefreshCw, Loader2, AlertCircle, - GripVertical, FolderTree, FileStack, Maximize2, @@ -58,7 +56,6 @@ interface FileExplorerPanelEnhancedProps { onFileSelect?: (path: string) => void; onFileOpen?: (path: string) => void; onToggle: () => void; - className?: string; } // 获取文件图标 @@ -140,7 +137,6 @@ export const FileExplorerPanelEnhanced: React.FC onFileSelect, onFileOpen, onToggle, - className, }) => { const { t } = useTranslation(); const [fileTree, setFileTree] = useState([]); @@ -153,57 +149,10 @@ export const FileExplorerPanelEnhanced: React.FC const [flattenedNodes, setFlattenedNodes] = useState([]); const [lastClickTime, setLastClickTime] = useState(0); const [lastClickPath, setLastClickPath] = useState(null); - const [width, setWidth] = useState(window.innerWidth * 0.15); // 15% of viewport width - const [isResizing, setIsResizing] = useState(false); const [viewMode, setViewMode] = useState<"tree" | "folder">("tree"); - const panelRef = useRef(null); - const resizeHandleRef = useRef(null); const unlistenRef = useRef(null); - // 响应窗口大小变化 - useEffect(() => { - const handleResize = () => { - // 保持15%的比例 - setWidth(window.innerWidth * 0.15); - }; - - window.addEventListener('resize', handleResize); - return () => window.removeEventListener('resize', handleResize); - }, []); - - // 处理拖拽调整宽度 - useEffect(() => { - const handleMouseMove = (e: MouseEvent) => { - if (!isResizing) return; - - const newWidth = e.clientX; - const minWidth = window.innerWidth * 0.1; // Min 10% - const maxWidth = window.innerWidth * 0.25; // Max 25% - if (newWidth >= minWidth && newWidth <= maxWidth) { - setWidth(newWidth); - } - }; - - const handleMouseUp = () => { - setIsResizing(false); - document.body.style.cursor = ''; - document.body.style.userSelect = ''; - }; - - if (isResizing) { - document.body.style.cursor = 'col-resize'; - document.body.style.userSelect = 'none'; - document.addEventListener('mousemove', handleMouseMove); - document.addEventListener('mouseup', handleMouseUp); - } - - return () => { - document.removeEventListener('mousemove', handleMouseMove); - document.removeEventListener('mouseup', handleMouseUp); - }; - }, [isResizing]); - // 切换节点展开状态 const toggleExpand = useCallback((path: string) => { setExpandedNodes((prev) => { diff --git a/src/components/GitPanelEnhanced.tsx b/src/components/GitPanelEnhanced.tsx index 5d0c327..996042e 100644 --- a/src/components/GitPanelEnhanced.tsx +++ b/src/components/GitPanelEnhanced.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useCallback, useRef } from "react"; -import { motion, AnimatePresence } from "framer-motion"; +import { AnimatePresence } from "framer-motion"; import { invoke } from "@tauri-apps/api/core"; import { GitBranch, @@ -14,7 +14,6 @@ import { FilePlus, FileX, FileDiff, - GripVertical, Check, Folder, FolderOpen, @@ -139,8 +138,6 @@ export const GitPanelEnhanced: React.FC = ({ const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [activeTab, setActiveTab] = useState("changes"); - const [width, setWidth] = useState(window.innerWidth * 0.15); // 15% of viewport width - const [isResizing, setIsResizing] = useState(false); const [expandedNodes, setExpandedNodes] = useState>(new Set()); const [selectedPath, setSelectedPath] = useState(null); const [showDiffViewer, setShowDiffViewer] = useState(false); @@ -148,56 +145,10 @@ export const GitPanelEnhanced: React.FC = ({ const [diffStaged, setDiffStaged] = useState(false); const panelRef = useRef(null); - const resizeHandleRef = useRef(null); const { t } = useTranslation(); const refreshIntervalRef = useRef(null); - // 响应窗口大小变化 - useEffect(() => { - const handleResize = () => { - // 保持15%的比例 - setWidth(window.innerWidth * 0.15); - }; - - window.addEventListener('resize', handleResize); - return () => window.removeEventListener('resize', handleResize); - }, []); - - // 处理拖拽调整宽度 - useEffect(() => { - const handleMouseMove = (e: MouseEvent) => { - if (!isResizing) return; - - const windowWidth = window.innerWidth; - const newWidth = windowWidth - e.clientX; - const minWidth = window.innerWidth * 0.1; // Min 10% - const maxWidth = window.innerWidth * 0.25; // Max 25% - - if (newWidth >= minWidth && newWidth <= maxWidth) { - setWidth(newWidth); - } - }; - - const handleMouseUp = () => { - setIsResizing(false); - document.body.style.cursor = ''; - document.body.style.userSelect = ''; - }; - - if (isResizing) { - document.body.style.cursor = 'col-resize'; - document.body.style.userSelect = 'none'; - document.addEventListener('mousemove', handleMouseMove); - document.addEventListener('mouseup', handleMouseUp); - } - - return () => { - document.removeEventListener('mousemove', handleMouseMove); - document.removeEventListener('mouseup', handleMouseUp); - }; - }, [isResizing]); - // 加载 Git 状态 const loadGitStatus = useCallback(async () => { if (!projectPath) return; @@ -210,6 +161,14 @@ export const GitPanelEnhanced: React.FC = ({ path: projectPath, // 修改参数名为 path }); + console.log('[GitPanelEnhanced] Git status loaded:', { + untracked: status.untracked, + untrackedCount: status.untracked.length, + staged: status.staged.length, + modified: status.modified.length, + conflicted: status.conflicted.length + }); + setGitStatus(status); } catch (err) { console.error("Failed to load git status:", err); @@ -552,9 +511,11 @@ export const GitPanelEnhanced: React.FC = ({ // 渲染文件列表(树形结构) const renderFileList = (files: GitFileStatus[], statusType: 'modified' | 'staged' | 'untracked' | 'conflicted') => { + console.log(`[GitPanelEnhanced] Rendering ${statusType} files:`, files); if (files.length === 0) return null; const fileTree = buildFileTree(files); + console.log(`[GitPanelEnhanced] Built file tree for ${statusType}:`, fileTree); return (
@@ -659,6 +620,26 @@ export const GitPanelEnhanced: React.FC = ({ )}
+ {/* Debug button */} + {/* 展开/收起按钮 */} @@ -780,6 +761,7 @@ export const GitPanelEnhanced: React.FC = ({
{gitStatus && ( <> + {console.log('[GitPanelEnhanced] Rendering all file lists with gitStatus:', gitStatus)} {renderFileList(gitStatus.staged, 'staged')} {renderFileList(gitStatus.modified, 'modified')} {renderFileList(gitStatus.untracked, 'untracked')}