Skip to content

Commit 2127345

Browse files
committed
Make truncated text easier to see in tooltip
1 parent fa760fe commit 2127345

File tree

5 files changed

+85
-14
lines changed

5 files changed

+85
-14
lines changed

src/components/chat-components/ContextBadges.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ExternalLink, FileText, Folder, Hash, X } from "lucide-react";
33
import { TFile } from "obsidian";
44
import { Badge } from "@/components/ui/badge";
55
import { Button } from "@/components/ui/button";
6+
import { TruncatedText } from "@/components/TruncatedText";
67

78
interface BaseContextBadgeProps {
89
onRemove?: () => void;
@@ -26,13 +27,17 @@ interface ContextFolderBadgeProps extends BaseContextBadgeProps {
2627
}
2728

2829
export function ContextNoteBadge({ note, isActive = false, onRemove }: ContextNoteBadgeProps) {
30+
const tooltipContent = <div className="tw-text-left">{note.path}</div>;
31+
2932
return (
3033
<Badge
3134
className={`tw-items-center tw-py-0 tw-pl-2 tw-text-xs ${onRemove ? "tw-pr-0.5" : "tw-pr-2"}`}
3235
>
3336
<div className="tw-flex tw-items-center tw-gap-1">
3437
<FileText className="tw-size-3" />
35-
<span className="tw-max-w-40 tw-truncate">{note.basename}</span>
38+
<TruncatedText className="tw-max-w-40" tooltipContent={tooltipContent}>
39+
{note.basename}
40+
</TruncatedText>
3641
{isActive && <span className="tw-text-xs tw-text-faint">Current</span>}
3742
{note.extension === "pdf" && <span className="tw-text-xs tw-text-faint">pdf</span>}
3843
</div>
@@ -68,7 +73,9 @@ export function ContextUrlBadge({ url, onRemove }: ContextUrlBadgeProps) {
6873
>
6974
<div className="tw-flex tw-items-center tw-gap-1">
7075
<ExternalLink className="tw-size-3" />
71-
<span className="tw-max-w-40 tw-truncate">{getDomain(url)}</span>
76+
<TruncatedText className="tw-max-w-40" tooltipContent={url}>
77+
{getDomain(url)}
78+
</TruncatedText>
7279
</div>
7380
{onRemove && (
7481
<Button
@@ -95,7 +102,9 @@ export function ContextTagBadge({ tag, onRemove }: ContextTagBadgeProps) {
95102
>
96103
<div className="tw-flex tw-items-center tw-gap-1">
97104
<Hash className="tw-size-3" />
98-
<span className="tw-max-w-40 tw-truncate">{displayTag}</span>
105+
<TruncatedText className="tw-max-w-40" tooltipContent={tag}>
106+
{displayTag}
107+
</TruncatedText>
99108
</div>
100109
{onRemove && (
101110
<Button
@@ -119,7 +128,9 @@ export function ContextFolderBadge({ folder, onRemove }: ContextFolderBadgeProps
119128
>
120129
<div className="tw-flex tw-items-center tw-gap-1">
121130
<Folder className="tw-size-3" />
122-
<span className="tw-max-w-40 tw-truncate">{folder}</span>
131+
<TruncatedText className="tw-max-w-40" tooltipContent={folder}>
132+
{folder}
133+
</TruncatedText>
123134
</div>
124135
{onRemove && (
125136
<Button

src/components/chat-components/pills/FolderPillNode.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,19 @@ export class FolderPillNode extends BasePillNode {
6969
* Override to display folder name wrapped in curly braces
7070
*/
7171
decorate(): JSX.Element {
72+
const tooltipContent = <div className="tw-text-left">{this.getFolderPath()}</div>;
73+
7274
return (
73-
<Badge variant="secondary" className="tw-inline-flex tw-items-center tw-gap-1 tw-text-xs">
74-
<TruncatedPillText content={this.getFolderPath()} openBracket="{" closeBracket="}" />
75+
<Badge
76+
variant="secondary"
77+
className="tw-mx-0.5 tw-inline-flex tw-items-center tw-gap-1 tw-px-2 tw-py-0 tw-align-middle tw-text-xs"
78+
>
79+
<TruncatedPillText
80+
content={this.getFolderPath()}
81+
openBracket="{"
82+
closeBracket="}"
83+
tooltipContent={tooltipContent}
84+
/>
7585
</Badge>
7686
);
7787
}

src/components/chat-components/pills/NotePillNode.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,20 @@ function NotePillComponent({ node }: NotePillComponentProps): JSX.Element {
144144
const isActive = node.getActive();
145145
const isPdf = notePath.toLowerCase().endsWith(".pdf");
146146

147+
const tooltipContent = <div className="tw-text-left">{notePath}</div>;
148+
147149
return (
148150
<Badge
149151
variant="secondary"
150-
className={cn("tw-mx-0.5 tw-items-center tw-px-2 tw-py-0 tw-text-xs")}
152+
className={cn("tw-mx-0.5 tw-items-center tw-px-2 tw-py-0 tw-align-middle tw-text-xs")}
151153
>
152154
<div className="tw-flex tw-items-center tw-gap-1">
153-
<TruncatedPillText content={noteTitle} openBracket="[[" closeBracket="]]" />
155+
<TruncatedPillText
156+
content={noteTitle}
157+
openBracket="[["
158+
closeBracket="]]"
159+
tooltipContent={tooltipContent}
160+
/>
154161
{isActive && <span className="tw-text-xs tw-text-faint">Current</span>}
155162
{isPdf && <span className="tw-text-xs tw-text-faint">pdf</span>}
156163
</div>

src/components/chat-components/pills/TagPillNode.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import React from "react";
12
import { $getRoot, DOMConversionMap, DOMConversionOutput, LexicalNode, NodeKey } from "lexical";
3+
import { Badge } from "@/components/ui/badge";
24
import { BasePillNode, SerializedBasePillNode } from "./BasePillNode";
5+
import { TruncatedPillText } from "./TruncatedPillText";
36

47
export interface SerializedTagPillNode extends SerializedBasePillNode {
58
type: "tag-pill";
@@ -59,6 +62,20 @@ export class TagPillNode extends BasePillNode {
5962
getTagName(): string {
6063
return this.getValue();
6164
}
65+
66+
/**
67+
* Override to display tag name with truncation and tooltip support
68+
*/
69+
decorate(): JSX.Element {
70+
return (
71+
<Badge
72+
variant="secondary"
73+
className="tw-mx-0.5 tw-inline-flex tw-items-center tw-gap-1 tw-px-2 tw-py-0 tw-align-middle tw-text-xs"
74+
>
75+
<TruncatedPillText content={this.getValue()} openBracket="" closeBracket="" />
76+
</Badge>
77+
);
78+
}
6279
}
6380

6481
function convertTagPillElement(domNode: HTMLElement): DOMConversionOutput | null {
Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import React from "react";
1+
import React, { useRef, useState } from "react";
22
import { cn } from "@/lib/utils";
3+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
34

45
interface TruncatedPillTextProps {
56
content: string;
67
openBracket: string;
78
closeBracket: string;
89
className?: string;
910
maxWidth?: string;
11+
tooltipContent?: React.ReactNode;
1012
}
1113

1214
/**
1315
* Component that truncates text content in the middle while preserving opening and closing brackets.
1416
* Shows ellipsis in the middle when content is too long, ensuring brackets are always visible.
17+
* Displays a tooltip with full content when text is truncated.
1518
*
1619
* @example
1720
* // Short text: [[Note Name]]
@@ -23,12 +26,35 @@ export function TruncatedPillText({
2326
closeBracket,
2427
className,
2528
maxWidth = "tw-max-w-40",
29+
tooltipContent,
2630
}: TruncatedPillTextProps): JSX.Element {
31+
const textRef = useRef<HTMLSpanElement | null>(null);
32+
const [open, setOpen] = useState<boolean>(false);
33+
34+
const onOpenChange = (isOpen: boolean): void => {
35+
// Only show tooltip if the text is actually truncated
36+
const isTruncated = textRef.current
37+
? textRef.current.offsetWidth < textRef.current.scrollWidth
38+
: false;
39+
setOpen(isOpen && isTruncated);
40+
};
41+
2742
return (
28-
<span className={cn("tw-inline-flex tw-items-center", maxWidth, className)}>
29-
<span className="tw-shrink-0">{openBracket}</span>
30-
<span className="tw-min-w-0 tw-truncate">{content}</span>
31-
<span className="tw-shrink-0">{closeBracket}</span>
32-
</span>
43+
<TooltipProvider delayDuration={300}>
44+
<Tooltip open={open} onOpenChange={onOpenChange}>
45+
<TooltipTrigger asChild>
46+
<span className={cn("tw-inline-flex tw-items-center", maxWidth, className)}>
47+
<span className="tw-shrink-0">{openBracket}</span>
48+
<span ref={textRef} className="tw-min-w-0 tw-truncate">
49+
{content}
50+
</span>
51+
<span className="tw-shrink-0">{closeBracket}</span>
52+
</span>
53+
</TooltipTrigger>
54+
<TooltipContent className="tw-max-w-64 tw-text-wrap tw-break-words">
55+
{tooltipContent || `${openBracket}${content}${closeBracket}`}
56+
</TooltipContent>
57+
</Tooltip>
58+
</TooltipProvider>
3359
);
3460
}

0 commit comments

Comments
 (0)