find widget fixes
This commit is contained in:
parent
d06e20acad
commit
61064d15a7
3 changed files with 45 additions and 20 deletions
|
|
@ -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<HTMLDivElement>((_, ref) => {
|
||||
const dispatch = useDispatch<AppDispatch>();
|
||||
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 ? (
|
||||
<></>
|
||||
) : (
|
||||
<TabBarContainer>
|
||||
<TabBarContainer ref={ref}>
|
||||
{tabs.map((tab) => (
|
||||
<Tab
|
||||
key={tab.id}
|
||||
|
|
@ -272,4 +271,4 @@ export function TabBar() {
|
|||
</TabBarSpace>
|
||||
</TabBarContainer>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<HTMLDivElement>) => {
|
||||
export const useFindWidget = (
|
||||
searchRef: RefObject<HTMLDivElement>,
|
||||
headerRef: RefObject<HTMLDivElement>,
|
||||
dependencies: React.DependencyList,
|
||||
) => {
|
||||
// Search input, debounced
|
||||
const [input, setInput] = useState<string>("");
|
||||
const debouncedInput = useRef<string>("");
|
||||
|
|
@ -159,13 +163,21 @@ export const useFindWidget = (searchRef: RefObject<HTMLDivElement>) => {
|
|||
});
|
||||
|
||||
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<HTMLDivElement>) => {
|
|||
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<HTMLDivElement>) => {
|
|||
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<HTMLDivElement>) => {
|
|||
}
|
||||
}
|
||||
},
|
||||
[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<HTMLDivElement>) => {
|
|||
|
||||
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([]);
|
||||
|
|
|
|||
|
|
@ -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<HTMLInputElement>(null);
|
||||
const stepsDivRef = useRef<HTMLDivElement>(null);
|
||||
const tabsRef = useRef<HTMLDivElement>(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" && <TabBar ref={tabsRef} />}
|
||||
{widget}
|
||||
|
||||
{!!showSessionTabs && mode !== "edit" && <TabBar />}
|
||||
|
||||
<StepsDiv
|
||||
ref={stepsDivRef}
|
||||
className={`mt-3 overflow-y-scroll pt-[8px] ${showScrollbar ? "thin-scrollbar" : "no-scrollbar"} ${history.length > 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) => (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue