From 978c6996afee4eb35bc99e611684ad8f6dfa393f Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 27 Oct 2024 08:54:43 -0400 Subject: [PATCH] Keep browser row from jumping height changes --- .../src/components/chat/BrowserSessionRow.tsx | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/webview-ui/src/components/chat/BrowserSessionRow.tsx b/webview-ui/src/components/chat/BrowserSessionRow.tsx index 0bf609d..46e715c 100644 --- a/webview-ui/src/components/chat/BrowserSessionRow.tsx +++ b/webview-ui/src/components/chat/BrowserSessionRow.tsx @@ -25,6 +25,7 @@ interface BrowserSessionRowProps { const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { const { messages, isLast, onHeightChange } = props const prevHeightRef = useRef(0) + const maxActionHeightRef = useRef(0) // Track max height of action section // Organize messages into pages with current state and next action const pages = useMemo(() => { @@ -140,6 +141,23 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => { screenshot: currentPage?.currentState.screenshot, } + const [actionContent, { height: actionHeight }] = useSize( +
+ {currentPage?.nextAction?.messages.map((message) => ( + + ))} +
+ ) + + useEffect(() => { + if (actionHeight === 0 || actionHeight === Infinity) { + return + } + if (actionHeight > maxActionHeightRef.current) { + maxActionHeightRef.current = actionHeight + } + }, [actionHeight]) + const [browserSessionRow, { height }] = useSize(
{
)}
+ - {/* Pagination */} + {/* Action content with min height */} +
{actionContent}
+ + {/* Pagination moved to bottom */} + {pages.length > 1 && (
@@ -237,12 +261,7 @@ const BrowserSessionRow = memo((props: BrowserSessionRowProps) => {
- - - {/* Show next action messages if they exist */} - {currentPage?.nextAction?.messages.map((message) => ( - - ))} + )} )