|
1 | | -import { forwardRef, memo, useEffect, useRef } from "react" |
| 1 | +import { forwardRef, useEffect, useRef } from "react" |
2 | 2 | import { Virtuoso, VirtuosoHandle } from "react-virtuoso" |
3 | 3 | import { cn } from "../../lib/utils" |
4 | 4 |
|
5 | 5 | interface CommandOutputViewerProps { |
6 | 6 | output: string |
7 | 7 | } |
8 | 8 |
|
9 | | -const CommandOutputViewer = memo( |
10 | | - forwardRef<HTMLDivElement, CommandOutputViewerProps>(({ output }, ref) => { |
11 | | - const virtuosoRef = useRef<VirtuosoHandle>(null) |
12 | | - const lines = output.split("\n") |
| 9 | +const CommandOutputViewer = forwardRef<HTMLDivElement, CommandOutputViewerProps>(({ output }, ref) => { |
| 10 | + const virtuosoRef = useRef<VirtuosoHandle>(null) |
| 11 | + const lines = output.split("\n") |
13 | 12 |
|
14 | | - useEffect(() => { |
15 | | - // Scroll to the bottom when output changes |
16 | | - if (virtuosoRef.current && typeof virtuosoRef.current.scrollToIndex === "function") { |
17 | | - virtuosoRef.current.scrollToIndex({ |
18 | | - index: lines.length - 1, |
19 | | - behavior: "auto", |
20 | | - }) |
21 | | - } |
22 | | - }, [output, lines.length]) |
| 13 | + useEffect(() => { |
| 14 | + // Scroll to the bottom when output changes |
| 15 | + if (virtuosoRef.current && typeof virtuosoRef.current.scrollToIndex === "function") { |
| 16 | + virtuosoRef.current.scrollToIndex({ |
| 17 | + index: lines.length - 1, |
| 18 | + behavior: "auto", |
| 19 | + }) |
| 20 | + } |
| 21 | + }, [output, lines.length]) |
23 | 22 |
|
24 | | - return ( |
25 | | - <div ref={ref} className="w-full rounded-b-md bg-[var(--vscode-editor-background)] h-[300px]"> |
26 | | - <Virtuoso |
27 | | - ref={virtuosoRef} |
28 | | - className="h-full" |
29 | | - totalCount={lines.length} |
30 | | - itemContent={(index) => ( |
31 | | - <div |
32 | | - className={cn( |
33 | | - "px-3 py-0.5", |
34 | | - "font-mono text-vscode-editor-foreground", |
35 | | - "text-[var(--vscode-editor-font-size,var(--vscode-font-size,12px))]", |
36 | | - "font-[var(--vscode-editor-font-family)]", |
37 | | - "whitespace-pre-wrap break-all anywhere", |
38 | | - )}> |
39 | | - {lines[index]} |
40 | | - </div> |
41 | | - )} |
42 | | - increaseViewportBy={{ top: 300, bottom: 300 }} |
43 | | - followOutput="auto" |
44 | | - /> |
45 | | - </div> |
46 | | - ) |
47 | | - }), |
48 | | -) |
| 23 | + return ( |
| 24 | + <div ref={ref} className="w-full rounded-b-md bg-[var(--vscode-editor-background)] h-[300px]"> |
| 25 | + <Virtuoso |
| 26 | + ref={virtuosoRef} |
| 27 | + className="h-full" |
| 28 | + totalCount={lines.length} |
| 29 | + itemContent={(index) => ( |
| 30 | + <div |
| 31 | + className={cn( |
| 32 | + "px-3 py-0.5", |
| 33 | + "font-mono text-vscode-editor-foreground", |
| 34 | + "text-[var(--vscode-editor-font-size,var(--vscode-font-size,12px))]", |
| 35 | + "font-[var(--vscode-editor-font-family)]", |
| 36 | + "whitespace-pre-wrap break-all anywhere", |
| 37 | + )}> |
| 38 | + {lines[index]} |
| 39 | + </div> |
| 40 | + )} |
| 41 | + increaseViewportBy={{ top: 300, bottom: 300 }} |
| 42 | + followOutput="auto" |
| 43 | + /> |
| 44 | + </div> |
| 45 | + ) |
| 46 | +}) |
49 | 47 |
|
50 | 48 | CommandOutputViewer.displayName = "CommandOutputViewer" |
51 | 49 |
|
|
0 commit comments