diff --git a/gui/src/components/TabBar/TabBar.tsx b/gui/src/components/TabBar/TabBar.tsx index 3b87a23c6..c54b02f3e 100644 --- a/gui/src/components/TabBar/TabBar.tsx +++ b/gui/src/components/TabBar/TabBar.tsx @@ -1,5 +1,5 @@ import { XMarkIcon } from "@heroicons/react/24/outline"; -import { useCallback, useEffect } from "react"; +import React, { useCallback, useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; import styled from "styled-components"; import { defaultBorderRadius } from ".."; @@ -143,7 +143,7 @@ const NewTabButton = styled.button` } `; -export function TabBar() { +export const TabBar = React.forwardRef((_, ref) => { const dispatch = useDispatch(); const currentSession = useSelector((state: RootState) => state.session); const currentSessionId = useSelector((state: RootState) => state.session.id); @@ -160,7 +160,6 @@ export function TabBar() { return Date.now().toString(36) + Math.random().toString(36).substring(2); }, []); - // Handle session changes useEffect(() => { if (!currentSessionId) return; @@ -246,7 +245,7 @@ export function TabBar() { return tabs.length === 1 ? ( <> ) : ( - + {tabs.map((tab) => ( ); -} +}); diff --git a/gui/src/components/find/FindWidget.tsx b/gui/src/components/find/FindWidget.tsx index fd174f59c..bc8f2168a 100644 --- a/gui/src/components/find/FindWidget.tsx +++ b/gui/src/components/find/FindWidget.tsx @@ -12,8 +12,8 @@ import { useState, } from "react"; import { HeaderButton, Input } from ".."; -import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; import { useAppSelector } from "../../redux/hooks"; +import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; interface SearchMatch { index: number; @@ -64,7 +64,11 @@ const HighlightOverlay = (props: HighlightOverlayProps) => { Container must have relative positioning */ -export const useFindWidget = (searchRef: RefObject) => { +export const useFindWidget = ( + searchRef: RefObject, + headerRef: RefObject, + dependencies: React.DependencyList, +) => { // Search input, debounced const [input, setInput] = useState(""); const debouncedInput = useRef(""); @@ -159,13 +163,21 @@ export const useFindWidget = (searchRef: RefObject) => { }); resizeObserver.observe(searchRef.current); + if (headerRef.current) { + resizeObserver.observe(headerRef.current); + } return () => { if (timeoutId) { clearTimeout(timeoutId); } - if (searchRef.current) resizeObserver.unobserve(searchRef.current); + if (searchRef.current) { + resizeObserver.unobserve(searchRef.current); + } + if (headerRef.current) { + resizeObserver.unobserve(headerRef.current); + } }; - }, [searchRef.current]); + }, [searchRef, headerRef]); // Main function for finding matches and generating highlight overlays const refreshSearch = useCallback( @@ -173,9 +185,10 @@ export const useFindWidget = (searchRef: RefObject) => { if (clearFirst) setMatches([]); const searchContainer = searchRef.current; + const header = headerRef.current; const _query = debouncedInput.current; // trimStart - decided no because spaces should be fully searchable - if (!searchContainer || !_query) { + if (!searchContainer || !_query || !header) { setMatches([]); return; } @@ -232,8 +245,13 @@ export const useFindWidget = (searchRef: RefObject) => { range.detach(); startIndex = endIndex; + const headerHeight = header.clientHeight; + const top = - rect.top + searchContainer.clientTop + searchContainer.scrollTop; + rect.top + + searchContainer.clientTop + + searchContainer.scrollTop - + headerHeight; const left = rect.left + searchContainer.clientLeft + searchContainer.scrollLeft; @@ -304,7 +322,15 @@ export const useFindWidget = (searchRef: RefObject) => { } } }, - [searchRef.current, debouncedInput, scrollToMatch, caseSensitive, useRegex], + [ + headerRef.current, + searchRef.current, + debouncedInput, + scrollToMatch, + caseSensitive, + useRegex, + ...dependencies, + ], ); // Triggers that should cause immediate refresh of results to closest search value: @@ -349,8 +375,8 @@ export const useFindWidget = (searchRef: RefObject) => { useEffect(() => { if (active || isResizing) setMatches([]); - else refreshSearch("none"); - }, [refreshSearch, active]); + else setTimeout(() => refreshSearch("none"), 300); // this gives plenty of time for resizing to finish + }, [refreshSearch, active, isResizing]); useEffect(() => { if (!open) setMatches([]); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 71b87c93a..0b16934c5 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -44,16 +44,17 @@ import { setDialogMessage, setShowDialog, } from "../../redux/slices/uiSlice"; +import { streamResponseThunk } from "../../redux/thunks"; import { cancelStream } from "../../redux/thunks/cancelStream"; import { streamEditThunk } from "../../redux/thunks/editMode"; import { loadLastSession } from "../../redux/thunks/session"; -import { streamResponseThunk } from "../../redux/thunks"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; import { FREE_TRIAL_LIMIT_REQUESTS, incrementFreeTrialCount, } from "../../util/freeTrial"; +import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; import CodeToEditCard from "../../components/mainInput/CodeToEditCard"; import EditModeDetails from "../../components/mainInput/EditModeDetails"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; @@ -61,7 +62,6 @@ import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { ToolCallDiv } from "./ToolCallDiv"; import { useAutoScroll } from "./useAutoScroll"; -import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; const StepsDiv = styled.div` position: relative; @@ -113,6 +113,7 @@ export function Chat() { const [stepsOpen] = useState<(boolean | undefined)[]>([]); const mainTextInputRef = useRef(null); const stepsDivRef = useRef(null); + const tabsRef = useRef(null); const history = useAppSelector((state) => state.session.history); const showChatScrollbar = useAppSelector( (state) => state.config.config.ui?.showChatScrollbar, @@ -152,7 +153,7 @@ export function Chat() { }; }, [isStreaming, jetbrains]); - const { widget, highlights } = useFindWidget(stepsDivRef); + const { widget, highlights } = useFindWidget(stepsDivRef, tabsRef, [history]); const currentToolCallApplyState = useAppSelector( selectCurrentToolCallApplyState, @@ -286,13 +287,12 @@ export function Chat() { return ( <> + {!!showSessionTabs && mode !== "edit" && } {widget} - {!!showSessionTabs && mode !== "edit" && } - 0 ? "flex-1" : ""}`} + className={`overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 0 ? "flex-1" : ""}`} > {highlights} {history.map((item, index: number) => (