fix: improve file path display truncation (#297)

* fix: tighten file path display rows

* fix: extract file explorer background menu
This commit is contained in:
Jinjing
2026-04-04 14:37:28 -07:00
committed by GitHub
parent e6435f1d61
commit c40cfb2cc2
5 changed files with 73 additions and 46 deletions
@@ -101,11 +101,11 @@ export function DiffSectionItem({
) : (
<ChevronDown className="size-3.5 shrink-0 text-muted-foreground" />
)}
<span className="font-medium">
{fileName}
{section.dirty && <span className="text-muted-foreground ml-1">M</span>}
<span className="min-w-0 flex-1 truncate">
<span className="font-medium">{fileName}</span>
{section.dirty && <span className="text-muted-foreground font-medium ml-1">M</span>}
{dirPath && <span className="text-muted-foreground text-xs ml-2">{dirPath}</span>}
</span>
{dirPath && <span className="text-muted-foreground text-xs">{dirPath}</span>}
<span
className={cn(
'text-xs font-bold ml-auto',
@@ -1,18 +1,13 @@
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useVirtualizer } from '@tanstack/react-virtual'
import { FilePlus, FolderPlus, Loader2 } from 'lucide-react'
import { Loader2 } from 'lucide-react'
import { useAppStore } from '@/store'
import { detectLanguage } from '@/lib/language-detect'
import { dirname, normalizeRelativePath } from '@/lib/path'
import { ScrollArea } from '@/components/ui/scroll-area'
import { cn } from '@/lib/utils'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
import { FileDeleteDialog } from './FileDeleteDialog'
import { FileExplorerBackgroundMenu } from './FileExplorerBackgroundMenu'
import { FileExplorerRow, InlineInputRow } from './FileExplorerRow'
import type { TreeNode } from './file-explorer-types'
import { splitPathSegments } from './path-tree'
@@ -394,31 +389,13 @@ export default function FileExplorer(): React.JSX.Element {
</div>
</ScrollArea>
<DropdownMenu open={bgMenuOpen} onOpenChange={setBgMenuOpen} modal={false}>
<DropdownMenuTrigger asChild>
<button
aria-hidden
tabIndex={-1}
className="pointer-events-none fixed size-px opacity-0"
style={{ left: bgMenuPoint.x, top: bgMenuPoint.y }}
/>
</DropdownMenuTrigger>
<DropdownMenuContent
className="w-48"
sideOffset={0}
align="start"
onCloseAutoFocus={(e) => e.preventDefault()}
>
<DropdownMenuItem onSelect={() => startNew('file', worktreePath, 0)}>
<FilePlus />
New File
</DropdownMenuItem>
<DropdownMenuItem onSelect={() => startNew('folder', worktreePath, 0)}>
<FolderPlus />
New Folder
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<FileExplorerBackgroundMenu
open={bgMenuOpen}
onOpenChange={setBgMenuOpen}
point={bgMenuPoint}
worktreePath={worktreePath}
onStartNew={startNew}
/>
<FileDeleteDialog
pendingDelete={pendingDelete}
@@ -0,0 +1,50 @@
import React from 'react'
import { FilePlus, FolderPlus } from 'lucide-react'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu'
export function FileExplorerBackgroundMenu({
open,
onOpenChange,
point,
worktreePath,
onStartNew
}: {
open: boolean
onOpenChange: (open: boolean) => void
point: { x: number; y: number }
worktreePath: string
onStartNew: (type: 'file' | 'folder', dir: string, depth: number) => void
}): React.JSX.Element {
return (
<DropdownMenu open={open} onOpenChange={onOpenChange} modal={false}>
<DropdownMenuTrigger asChild>
<button
aria-hidden
tabIndex={-1}
className="pointer-events-none fixed size-px opacity-0"
style={{ left: point.x, top: point.y }}
/>
</DropdownMenuTrigger>
<DropdownMenuContent
className="w-48"
sideOffset={0}
align="start"
onCloseAutoFocus={(e) => e.preventDefault()}
>
<DropdownMenuItem onSelect={() => onStartNew('file', worktreePath, 0)}>
<FilePlus />
New File
</DropdownMenuItem>
<DropdownMenuItem onSelect={() => onStartNew('folder', worktreePath, 0)}>
<FolderPlus />
New Folder
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}
@@ -74,10 +74,12 @@ export function FileResultRow({
)}
/>
<File size={12} className="flex-shrink-0 text-muted-foreground" />
<span className="text-xs text-foreground truncate">{fileName}</span>
{dirPath && (
<span className="text-[10px] text-muted-foreground truncate ml-1">{dirPath}</span>
)}
<span className="min-w-0 flex-1 truncate text-left text-xs">
<span className="text-foreground">{fileName}</span>
{dirPath && (
<span className="ml-1.5 text-[10px] text-muted-foreground">{dirPath}</span>
)}
</span>
<span className="ml-auto text-[10px] text-muted-foreground flex-shrink-0 bg-muted/80 rounded-full px-1.5">
{fileResult.matches.length}
</span>
@@ -943,12 +943,10 @@ function UncommittedEntryRow({
>
<StatusIcon className="size-3.5 shrink-0" style={{ color: STATUS_COLORS[entry.status] }} />
<div className="min-w-0 flex-1 text-xs">
<div className="flex items-center gap-1.5">
<span className="min-w-0 truncate text-foreground">{fileName}</span>
{dirPath && (
<span className="truncate text-[11px] text-muted-foreground">{dirPath}</span>
)}
</div>
<span className="min-w-0 block truncate">
<span className="text-foreground">{fileName}</span>
{dirPath && <span className="ml-1.5 text-[11px] text-muted-foreground">{dirPath}</span>}
</span>
{conflictLabel && (
<div className="truncate text-[11px] text-muted-foreground">{conflictLabel}</div>
)}