mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Remove react-text-truncate and use custom 'see more' button in task header
This commit is contained in:
14
webview-ui/package-lock.json
generated
14
webview-ui/package-lock.json
generated
@@ -21,7 +21,6 @@
|
|||||||
"react-markdown": "^9.0.1",
|
"react-markdown": "^9.0.1",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"react-syntax-highlighter": "^15.5.0",
|
"react-syntax-highlighter": "^15.5.0",
|
||||||
"react-text-truncate": "^0.19.0",
|
|
||||||
"react-textarea-autosize": "^8.5.3",
|
"react-textarea-autosize": "^8.5.3",
|
||||||
"react-use": "^17.5.1",
|
"react-use": "^17.5.1",
|
||||||
"react-virtuoso": "^4.7.13",
|
"react-virtuoso": "^4.7.13",
|
||||||
@@ -17453,19 +17452,6 @@
|
|||||||
"react": ">= 0.14.0"
|
"react": ">= 0.14.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-text-truncate": {
|
|
||||||
"version": "0.19.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/react-text-truncate/-/react-text-truncate-0.19.0.tgz",
|
|
||||||
"integrity": "sha512-QxHpZABfGG0Z3WEYbRTZ+rXdZn50Zvp+sWZXgVAd7FCKAMzv/kcwctTpNmWgXDTpAoHhMjOVwmgRtX3x5yeF4w==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"prop-types": "^15.5.7"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": "^15.4.1 || ^16.0.0 || ^17.0.0 || || ^18.0.0",
|
|
||||||
"react-dom": "^15.4.1 || ^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/react-textarea-autosize": {
|
"node_modules/react-textarea-autosize": {
|
||||||
"version": "8.5.3",
|
"version": "8.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/react-textarea-autosize/-/react-textarea-autosize-8.5.3.tgz",
|
"resolved": "https://registry.npmjs.org/react-textarea-autosize/-/react-textarea-autosize-8.5.3.tgz",
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
"react-markdown": "^9.0.1",
|
"react-markdown": "^9.0.1",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "5.0.1",
|
||||||
"react-syntax-highlighter": "^15.5.0",
|
"react-syntax-highlighter": "^15.5.0",
|
||||||
"react-text-truncate": "^0.19.0",
|
|
||||||
"react-textarea-autosize": "^8.5.3",
|
"react-textarea-autosize": "^8.5.3",
|
||||||
"react-use": "^17.5.1",
|
"react-use": "^17.5.1",
|
||||||
"react-virtuoso": "^4.7.13",
|
"react-virtuoso": "^4.7.13",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
|
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
|
||||||
import React, { useEffect, useRef, useState } from "react"
|
import React, { useEffect, useRef, useState } from "react"
|
||||||
import TextTruncate from "react-text-truncate"
|
|
||||||
import { useWindowSize } from "react-use"
|
import { useWindowSize } from "react-use"
|
||||||
import { ClaudeMessage } from "../../../src/shared/ExtensionMessage"
|
import { ClaudeMessage } from "../../../src/shared/ExtensionMessage"
|
||||||
import { vscode } from "../utils/vscode"
|
import { vscode } from "../utils/vscode"
|
||||||
@@ -17,8 +16,9 @@ interface TaskHeaderProps {
|
|||||||
|
|
||||||
const TaskHeader: React.FC<TaskHeaderProps> = ({ task, tokensIn, tokensOut, totalCost, onClose, isHidden }) => {
|
const TaskHeader: React.FC<TaskHeaderProps> = ({ task, tokensIn, tokensOut, totalCost, onClose, isHidden }) => {
|
||||||
const [isExpanded, setIsExpanded] = useState(false)
|
const [isExpanded, setIsExpanded] = useState(false)
|
||||||
const [textTruncateKey, setTextTruncateKey] = useState(0)
|
const [showSeeMore, setShowSeeMore] = useState(false)
|
||||||
const textContainerRef = useRef<HTMLDivElement>(null)
|
const textContainerRef = useRef<HTMLDivElement>(null)
|
||||||
|
const textRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
When dealing with event listeners in React components that depend on state variables, we face a challenge. We want our listener to always use the most up-to-date version of a callback function that relies on current state, but we don't want to constantly add and remove event listeners as that function updates. This scenario often arises with resize listeners or other window events. Simply adding the listener in a useEffect with an empty dependency array risks using stale state, while including the callback in the dependencies can lead to unnecessary re-registrations of the listener. There are react hook libraries that provide a elegant solution to this problem by utilizing the useRef hook to maintain a reference to the latest callback function without triggering re-renders or effect re-runs. This approach ensures that our event listener always has access to the most current state while minimizing performance overhead and potential memory leaks from multiple listener registrations.
|
When dealing with event listeners in React components that depend on state variables, we face a challenge. We want our listener to always use the most up-to-date version of a callback function that relies on current state, but we don't want to constantly add and remove event listeners as that function updates. This scenario often arises with resize listeners or other window events. Simply adding the listener in a useEffect with an empty dependency array risks using stale state, while including the callback in the dependencies can lead to unnecessary re-registrations of the listener. There are react hook libraries that provide a elegant solution to this problem by utilizing the useRef hook to maintain a reference to the latest callback function without triggering re-renders or effect re-runs. This approach ensures that our event listener always has access to the most current state while minimizing performance overhead and potential memory leaks from multiple listener registrations.
|
||||||
@@ -52,25 +52,29 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({ task, tokensIn, tokensOut, tota
|
|||||||
After:
|
After:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { height: windowHeight } = useWindowSize()
|
const { height: windowHeight, width: windowWidth } = useWindowSize()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isExpanded && textContainerRef.current) {
|
if (isExpanded && textContainerRef.current) {
|
||||||
const maxHeight = windowHeight * (3 / 5)
|
const maxHeight = windowHeight * (1 / 2)
|
||||||
textContainerRef.current.style.maxHeight = `${maxHeight}px`
|
textContainerRef.current.style.maxHeight = `${maxHeight}px`
|
||||||
}
|
}
|
||||||
}, [isExpanded, windowHeight])
|
}, [isExpanded, windowHeight])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isHidden) {
|
if (textRef.current && textContainerRef.current) {
|
||||||
/*
|
let textContainerHeight = textContainerRef.current.clientHeight
|
||||||
There's an issue with TextTruncate where it is hidden when removed from the screen. It uses canvas to measure text width and adjusts the content accordingly. However, when the component is hidden, the canvas is not rendered and the text is not measured.
|
if (!textContainerHeight) {
|
||||||
We can fix this by forcing re-render after navigation by using a key prop that changes when you navigate back to the page.
|
textContainerHeight = textContainerRef.current.getBoundingClientRect().height
|
||||||
- https://github.com/ShinyChang/React-Text-Truncate?tab=readme-ov-file#faq
|
}
|
||||||
*/
|
const isOverflowing = textRef.current.scrollHeight > textContainerHeight
|
||||||
setTextTruncateKey((prev) => prev + 1)
|
// necessary to show see more button again if user resizes window to expand and then back to collapse
|
||||||
|
if (!isOverflowing) {
|
||||||
|
setIsExpanded(false)
|
||||||
|
}
|
||||||
|
setShowSeeMore(isOverflowing)
|
||||||
}
|
}
|
||||||
}, [isHidden])
|
}, [task.text, windowWidth])
|
||||||
|
|
||||||
const toggleExpand = () => setIsExpanded(!isExpanded)
|
const toggleExpand = () => setIsExpanded(!isExpanded)
|
||||||
|
|
||||||
@@ -112,40 +116,68 @@ const TaskHeader: React.FC<TaskHeaderProps> = ({ task, tokensIn, tokensOut, tota
|
|||||||
overflowY: isExpanded ? "auto" : "hidden",
|
overflowY: isExpanded ? "auto" : "hidden",
|
||||||
wordBreak: "break-word",
|
wordBreak: "break-word",
|
||||||
overflowWrap: "anywhere",
|
overflowWrap: "anywhere",
|
||||||
|
position: "relative",
|
||||||
}}>
|
}}>
|
||||||
<TextTruncate
|
<div
|
||||||
key={textTruncateKey}
|
ref={textRef}
|
||||||
line={isExpanded ? 0 : 3}
|
style={{
|
||||||
element="span"
|
display: "-webkit-box",
|
||||||
truncateText="…"
|
WebkitLineClamp: isExpanded ? "unset" : 3,
|
||||||
text={task.text}
|
WebkitBoxOrient: "vertical",
|
||||||
textTruncateChild={
|
overflow: "hidden",
|
||||||
<span
|
whiteSpace: "pre-wrap",
|
||||||
|
wordBreak: "break-word",
|
||||||
|
overflowWrap: "anywhere",
|
||||||
|
}}>
|
||||||
|
{task.text}
|
||||||
|
</div>
|
||||||
|
{!isExpanded && showSeeMore && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: "absolute",
|
||||||
|
right: 0,
|
||||||
|
bottom: 0,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
}}>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: 30,
|
||||||
|
height: "1.2em",
|
||||||
|
background:
|
||||||
|
"linear-gradient(to right, transparent, var(--vscode-badge-background))",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
style={{
|
style={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
color: "var(--vscode-textLink-foreground)",
|
color: "var(--vscode-textLink-foreground)",
|
||||||
marginLeft: "5px",
|
paddingRight: 0,
|
||||||
|
paddingLeft: 3,
|
||||||
|
backgroundColor: "var(--vscode-badge-background)",
|
||||||
}}
|
}}
|
||||||
onClick={toggleExpand}>
|
onClick={toggleExpand}>
|
||||||
See more
|
See more
|
||||||
</span>
|
</div>
|
||||||
}
|
</div>
|
||||||
/>
|
|
||||||
{isExpanded && (
|
|
||||||
<span
|
|
||||||
style={{
|
|
||||||
cursor: "pointer",
|
|
||||||
color: "var(--vscode-textLink-foreground)",
|
|
||||||
marginLeft: "5px",
|
|
||||||
}}
|
|
||||||
onClick={toggleExpand}>
|
|
||||||
See less
|
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{isExpanded && showSeeMore && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
cursor: "pointer",
|
||||||
|
color: "var(--vscode-textLink-foreground)",
|
||||||
|
marginLeft: "auto",
|
||||||
|
textAlign: "right",
|
||||||
|
paddingRight: 0,
|
||||||
|
}}
|
||||||
|
onClick={toggleExpand}>
|
||||||
|
See less
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{task.images && task.images.length > 0 && <Thumbnails images={task.images} />}
|
{task.images && task.images.length > 0 && <Thumbnails images={task.images} />}
|
||||||
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
|
<div style={{ display: "flex", flexDirection: "column", gap: "4px" }}>
|
||||||
<div style={{ display: "flex", alignItems: "center", gap: "4px" }}>
|
<div style={{ display: "flex", alignItems: "center", gap: "4px", flexWrap: "wrap" }}>
|
||||||
<span style={{ fontWeight: "bold" }}>Tokens:</span>
|
<span style={{ fontWeight: "bold" }}>Tokens:</span>
|
||||||
<span style={{ display: "flex", alignItems: "center", gap: "3px" }}>
|
<span style={{ display: "flex", alignItems: "center", gap: "3px" }}>
|
||||||
<i
|
<i
|
||||||
|
|||||||
Reference in New Issue
Block a user