Elffuss BraidHub

kikocis/continue public

works with tab resize now
Changesetcd22093c507b599034a4e7f14ac6a6e1cfb1aeb8ca243d3255870d077226fd27
AuthorDallin Romney <dallinromney@gmail.com> · 2025-05-23 16:58 -07:00
CommitterDallin Romney <dallinromney@gmail.com> · 2025-05-23 16:58 -07:00
Parents4a5fab4dde7e

Browse the files at this changeset

8 files changed

modified gui/src/components/TabBar/TabBar.tsx +9 −4
@@ -35,6 +35,8 @@
3535 border-bottom: none;
3636 position: relative;
3737 margin-top: 2px;
38+ max-height: 100px;
39+ overflow: auto;
3840
3941 /* Hide scrollbar but keep functionality */
4042 scrollbar-width: none;
@@ -223,10 +225,13 @@
223225 }
224226 };
225227
226- return tabs.length === 1 ? (
227- <></>
228- ) : (
229- <TabBarContainer ref={ref}>
228+ return (
229+ <TabBarContainer
230+ ref={ref}
231+ style={{
232+ display: tabs.length === 1 ? "none" : "flex",
233+ }}
234+ >
230235 {tabs.map((tab) => (
231236 <Tab
232237 key={tab.id}
modified gui/src/components/find/FindWidget.tsx +22 −17
@@ -3,7 +3,14 @@
33 ArrowUpIcon,
44 XMarkIcon,
55 } from "@heroicons/react/24/outline";
6-import { RefObject, useCallback, useEffect, useMemo, useState } from "react";
6+import {
7+ RefObject,
8+ useCallback,
9+ useEffect,
10+ useMemo,
11+ useRef,
12+ useState,
13+} from "react";
714 import { HeaderButton, Input } from "..";
815 import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
916 import {
@@ -11,8 +18,8 @@
1118 SearchMatch,
1219 searchWithinContainer,
1320 } from "./findWidgetSearch";
14-import { useDebouncedInput } from "./useDebouncedInput";
15-import { useElementSize } from "./useElementDims";
21+import useDebounceValue from "./useDebounce";
22+import { useElementSize } from "./useElementSize";
1623
1724 interface HighlightOverlayProps {
1825 rectangle: Rectangle;
@@ -51,15 +58,12 @@
5158 export const useFindWidget = (
5259 searchRef: RefObject<HTMLDivElement>,
5360 headerRef: RefObject<HTMLDivElement>,
54- refreshDependencies: React.DependencyList,
5561 disabled: boolean,
5662 ) => {
5763 // Search input, debounced
58- const {
59- inputRef,
60- debouncedValue: searchTerm,
61- currentValue,
62- } = useDebouncedInput();
64+ const inputRef = useRef<HTMLInputElement>(null);
65+ const [currentValue, setCurrentValue] = useState<string>("");
66+ const searchTerm = useDebounceValue(currentValue, 300);
6367
6468 // Widget open/closed state
6569 const [open, setOpen] = useState<boolean>(false);
@@ -134,14 +138,12 @@
134138 }, [inputRef, matches, nextMatch]);
135139
136140 // Handle container resize changes - highlight positions must adjust
137- const headerSize = useElementSize(headerRef);
138- const containerSize = useElementSize(searchRef);
141+ const { clientHeight: headerHeight, isResizing: headerResizing } =
142+ useElementSize(headerRef);
143+ const { isResizing: containerResizing } = useElementSize(searchRef);
139144 const isResizing = useMemo(() => {
140- return containerSize.isResizing || headerSize.isResizing;
141- }, [containerSize, headerSize]);
142- const headerHeight = useMemo(() => {
143- return headerSize.size.height;
144- }, [headerSize]);
145+ return containerResizing || headerResizing;
146+ }, [containerResizing, headerResizing]);
145147
146148 // Main function for finding matches and generating highlight overlays
147149 const refreshSearch = useCallback(
@@ -192,7 +194,7 @@
192194 } else {
193195 refreshSearch("closest");
194196 }
195- }, [refreshSearch, open, disabled, isResizing, ...refreshDependencies]);
197+ }, [refreshSearch, open, disabled, isResizing]);
196198
197199 // Clicks in search div can cause content changes that for some reason don't trigger resize
198200 // Refresh clicking within container
@@ -220,6 +222,9 @@
220222 type="text"
221223 ref={inputRef}
222224 value={currentValue}
225+ onChange={(e) => {
226+ setCurrentValue(e.target.value);
227+ }}
223228 placeholder="Search..."
224229 />
225230 <p className="xs:block hidden min-w-12 whitespace-nowrap px-1 text-center text-xs">
modified gui/src/components/find/findWidgetSearch.ts +4 −3
@@ -87,9 +87,10 @@
8787 startIndex = endIndex;
8888
8989 const top =
90- rect.top + searchContainer.clientTop + searchContainer.scrollTop;
91- // -
92- // options.offsetHeight;
90+ rect.top +
91+ searchContainer.clientTop +
92+ searchContainer.scrollTop -
93+ options.offsetHeight;
9394
9495 const left =
9596 rect.left + searchContainer.clientLeft + searchContainer.scrollLeft;
added gui/src/components/find/useDebounce.ts +19 −0
@@ -0,0 +1,19 @@
1+import { useEffect, useState } from "react";
2+
3+function useDebounceValue<T>(value: T, delay: number = 500): T {
4+ const [debouncedValue, setDebouncedValue] = useState<T>(value);
5+
6+ useEffect(() => {
7+ const timer = setTimeout(() => {
8+ setDebouncedValue(value);
9+ }, delay);
10+
11+ return () => {
12+ clearTimeout(timer);
13+ };
14+ }, [value, delay]);
15+
16+ return debouncedValue;
17+}
18+
19+export default useDebounceValue;
deleted gui/src/components/find/useDebouncedInput.ts +0 −48
@@ -1,48 +0,0 @@
1-import { debounce } from "lodash";
2-import { useEffect, useRef, useState } from "react";
3-
4-interface UseDebouncedInputResult {
5- inputRef: React.RefObject<HTMLInputElement>;
6- debouncedValue: string;
7- currentValue: string;
8-}
9-
10-export const useDebouncedInput = (
11- debounceDelay: number = 300,
12-): UseDebouncedInputResult => {
13- const [debouncedValue, setDebouncedValue] = useState("");
14- const [currentValue, setCurrentValue] = useState("");
15- const inputRef = useRef<HTMLInputElement>(null);
16-
17- const debouncedSetValue = useRef(
18- debounce((value: string) => {
19- setDebouncedValue(value);
20- }, debounceDelay),
21- ).current;
22-
23- useEffect(() => {
24- debouncedSetValue(currentValue);
25- // Initial value is set immediately
26- if (currentValue === "") {
27- setDebouncedValue("");
28- }
29-
30- return () => {
31- debouncedSetValue.cancel();
32- };
33- }, [currentValue, debouncedSetValue]);
34-
35- useEffect(() => {
36- const input = inputRef.current;
37- if (!input) return;
38-
39- const handleChange = (event: Event) => {
40- setCurrentValue((event.target as HTMLInputElement).value);
41- };
42-
43- input.addEventListener("input", handleChange);
44- return () => input.removeEventListener("input", handleChange);
45- }, []);
46-
47- return { inputRef, debouncedValue, currentValue };
48-};
deleted gui/src/components/find/useElementDims.ts +0 −42
@@ -1,42 +0,0 @@
1-import { debounce } from "lodash";
2-import { useEffect, useState } from "react";
3-
4-export function useElementSize(
5- ref: React.RefObject<HTMLElement>,
6- resizeDebounce = 200,
7-) {
8- const [size, setSize] = useState({
9- height: 0,
10- width: 0,
11- });
12- const [isResizing, setIsResizing] = useState(false);
13-
14- useEffect(() => {
15- if (!ref.current) return;
16-
17- const element = ref.current;
18- const debouncedSetSize = debounce((entries: ResizeObserverEntry[]) => {
19- if (!entries.length) return;
20-
21- setIsResizing(false);
22- setSize({
23- height: entries[0].contentRect.height,
24- width: entries[0].contentRect.width,
25- });
26- }, resizeDebounce);
27-
28- const resizeObserver = new ResizeObserver((entries) => {
29- setIsResizing(true);
30- debouncedSetSize(entries);
31- });
32- resizeObserver.observe(element);
33-
34- return () => {
35- debouncedSetSize.cancel();
36- resizeObserver.unobserve(element);
37- resizeObserver.disconnect();
38- };
39- }, [ref, resizeDebounce]);
40-
41- return { ref, size, isResizing };
42-}
added gui/src/components/find/useElementSize.ts +81 −0
@@ -0,0 +1,81 @@
1+import { RefObject, useCallback, useEffect, useState } from "react";
2+
3+interface ElementSize {
4+ clientWidth: number;
5+ clientHeight: number;
6+ scrollWidth: number;
7+ scrollHeight: number;
8+ isResizing: boolean;
9+}
10+
11+interface UseElementSizeOptions {
12+ debounceMs?: number;
13+}
14+
15+export const useElementSize = (
16+ ref: RefObject<HTMLElement>,
17+ debounceMs = 250,
18+): ElementSize => {
19+ const [size, setSize] = useState<ElementSize>({
20+ clientWidth: 0,
21+ clientHeight: 0,
22+ scrollWidth: 0,
23+ scrollHeight: 0,
24+ isResizing: false,
25+ });
26+
27+ // Debounced update function
28+ const debouncedSetSize = useCallback(
29+ (measurements: Omit<ElementSize, "isResizing">) => {
30+ let timeoutId: NodeJS.Timeout;
31+
32+ setSize((prev) => ({ ...prev, isResizing: true }));
33+
34+ timeoutId = setTimeout(() => {
35+ setSize({
36+ ...measurements,
37+ isResizing: false,
38+ });
39+ }, debounceMs);
40+
41+ return () => clearTimeout(timeoutId);
42+ },
43+ [debounceMs],
44+ );
45+
46+ useEffect(() => {
47+ if (!ref.current) return;
48+
49+ const updateSize = () => {
50+ const element = ref.current;
51+ if (!element) return;
52+
53+ const measurements = {
54+ clientWidth: element.clientWidth,
55+ clientHeight: element.clientHeight,
56+ scrollWidth: element.scrollWidth,
57+ scrollHeight: element.scrollHeight,
58+ };
59+
60+ debouncedSetSize(measurements);
61+ };
62+
63+ // Create ResizeObserver instance
64+ const resizeObserver = new ResizeObserver(() => {
65+ updateSize();
66+ });
67+
68+ // Start observing the element
69+ resizeObserver.observe(ref.current);
70+
71+ // Initial size calculation
72+ updateSize();
73+
74+ // Cleanup
75+ return () => {
76+ resizeObserver.disconnect();
77+ };
78+ }, [ref, debouncedSetSize]);
79+
80+ return size;
81+};
modified gui/src/pages/gui/Chat.tsx +0 −1
@@ -156,7 +156,6 @@
156156 const { widget, highlights } = useFindWidget(
157157 stepsDivRef,
158158 tabsRef,
159- [history],
160159 isStreaming,
161160 );
162161