fix(webui): preserve inferred file reference text (#6672)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-15 20:30:07 +08:00
1 parent 96eb1ace6f
commit 4ebd75623f
7 files changed
+138 -14

No files matched your search

+10 -7
View File
@@ -35,7 +35,7 @@ export type FileReferenceKind =
interface FileReferenceChipProps {
path: string;
tooltipPath?: string;
display?: "name" | "path";
display?: "name" | "path" | "inline-code";
showIcon?: boolean;
truncateFromStart?: boolean;
active?: boolean;
@@ -62,7 +62,8 @@ export function FileReferenceChip({
const { t } = useTranslation();
const [tooltipOpen, setTooltipOpen] = useState(false);
const { directory, name } = splitFilePath(path);
const displayText = display === "path" ? path.replace(/\\/g, "/") : name;
const inlineCode = display === "inline-code";
const displayText = inlineCode ? path : display === "path" ? path.replace(/\\/g, "/") : name;
const fullPath = tooltipPath || path;
const targetPath = previewPath || tooltipPath || path;
const kind = fileKindForPath(targetPath);
@@ -75,19 +76,19 @@ export function FileReferenceChip({
setTooltipOpen(false);
onOpen(targetPath);
};
const Text = truncateFromStart ? StartTruncatedText : "span";
const Text = inlineCode ? "code" : truncateFromStart ? StartTruncatedText : "span";
const onKeyDown = (event: KeyboardEvent) => {
if (event.key !== "Enter" && event.key !== " ") return;
openPreview(event);
};
return (
<FileActions path={targetPath} className={truncateFromStart ? "min-w-0" : undefined}>
<FileActions path={targetPath} className={cn(truncateFromStart && "min-w-0", inlineCode && "inline")}>
<TooltipProvider>
<Tooltip open={tooltipOpen} onOpenChange={setTooltipOpen}>
<TooltipTrigger asChild>
<span
onContextMenuCapture={() => setTooltipOpen(false)}
className={cn("not-prose inline-flex max-w-full align-baseline leading-[inherit]", truncateFromStart && "min-w-0", className)}
className={cn("not-prose inline-flex max-w-full align-baseline leading-[inherit]", truncateFromStart && "min-w-0", inlineCode && "inline", className)}
>
<span
data-testid={testId}
@@ -99,6 +100,7 @@ export function FileReferenceChip({
className={cn(
"inline-flex max-w-full items-baseline gap-[0.28em] font-medium leading-[inherit]",
truncateFromStart && "min-w-0",
inlineCode && "inline",
interactive
? "text-content-link transition-colors hover:text-content-link-hover"
: "text-muted-foreground",
@@ -108,12 +110,13 @@ export function FileReferenceChip({
],
)}
>
{showIcon ? <FileReferenceIcon kind={kind} className="translate-y-[0.12em]" /> : null}
{showIcon ? <FileReferenceIcon kind={kind} className={cn("translate-y-[0.12em]", inlineCode && "mr-[0.28em] inline-block")} /> : null}
<Text
data-sheen-text={active ? displayText : undefined}
className={cn(
"min-w-0 max-w-full",
!truncateFromStart && "[overflow-wrap:anywhere] sm:truncate",
!inlineCode && !truncateFromStart && "[overflow-wrap:anywhere] sm:truncate",
inlineCode && "markdown-inline-code whitespace-break-spaces font-mono text-inherit [overflow-wrap:anywhere]",
active && !truncateFromStart && "streaming-text-sheen file-reference-sheen",
textClassName,
)}
@@ -555,6 +555,7 @@ export default function MarkdownTextRenderer({
return (
<AvailableFileReferenceChip
path={raw}
display="inline-code"
onOpen={onOpenFilePreview}
/>
);