Enhance text overflow handling in TaskHeader component (#7674)

This commit is contained in:
Saoud Rizwan authored and GitHub committed 2025-11-25 14:23:39 -08:00
1 parent 852a7c9198
commit 0caeea1b37
1 file changed
+16 -10
@@ -1,7 +1,7 @@
import { ClineMessage } from "@shared/ExtensionMessage"
import { StringRequest } from "@shared/proto/cline/common"
import { ChevronDownIcon, ChevronRightIcon } from "lucide-react"
import React, { useCallback, useMemo, useState } from "react"
import React, { useCallback, useLayoutEffect, useMemo, useState } from "react"
import Thumbnails from "@/components/common/Thumbnails"
import { getModeSpecificFields, normalizeApiConfiguration } from "@/components/settings/utils/providerUtils"
import { useExtensionState } from "@/context/ExtensionStateContext"
@@ -61,14 +61,19 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
} = useExtensionState()
const [isHighlightedTextExpanded, setIsHighlightedTextExpanded] = useState(false)
const [isTextOverflowing, setIsTextOverflowing] = useState(false)
const highlightedTextRef = React.useRef<HTMLDivElement>(null)
const { highlightedText, displayTextExpandable } = useMemo(() => {
const taskTextLines = task.text?.split("\n") || []
const highlightedText = highlightText(task.text, false)
const highlightedText = useMemo(() => highlightText(task.text, false), [task.text])
return { highlightedText, displayTextExpandable: taskTextLines.length > 3 }
}, [task.text])
// Check if text overflows the container (i.e., needs clamping)
useLayoutEffect(() => {
const el = highlightedTextRef.current
if (el && isTaskExpanded && !isHighlightedTextExpanded) {
// Check if content height exceeds the max-height
setIsTextOverflowing(el.scrollHeight > el.clientHeight)
}
}, [task.text, isTaskExpanded, isHighlightedTextExpanded])
// Handle click outside to collapse
React.useEffect(() => {
@@ -175,16 +180,17 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({
<div className="flex flex-col break-words" key={`task-details-${currentTaskItem?.id}`}>
<div
className={cn(
"ph-no-capture whitespace-pre-wrap break-words px-0.5 text-sm cursor-pointer mt-1 relative",
"ph-no-capture whitespace-pre-wrap break-words px-0.5 text-sm mt-1 relative",
"max-h-[4.5rem] overflow-hidden",
{
"max-h-[25vh] overflow-y-auto scroll-smooth": isHighlightedTextExpanded,
"max-h-[4.5rem] overflow-hidden": !isHighlightedTextExpanded && displayTextExpandable,
"cursor-pointer": isTextOverflowing,
},
)}
onClick={() => displayTextExpandable && setIsHighlightedTextExpanded(true)}
onClick={() => isTextOverflowing && setIsHighlightedTextExpanded(true)}
ref={highlightedTextRef}
style={
!isHighlightedTextExpanded && displayTextExpandable
!isHighlightedTextExpanded && isTextOverflowing
? {
WebkitMaskImage: "linear-gradient(to bottom, black 60%, transparent 100%)",
maskImage: "linear-gradient(to bottom, black 60%, transparent 100%)",