From 2deb870bb67ba7827612f792ab9bdcfd298015cb Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 2 Nov 2025 05:52:36 -0800 Subject: [PATCH] Fix pair editor --- src-web/components/core/PairEditor.tsx | 251 +++++++++++-------------- 1 file changed, 112 insertions(+), 139 deletions(-) diff --git a/src-web/components/core/PairEditor.tsx b/src-web/components/core/PairEditor.tsx index 9f564ac0..32287c2f 100644 --- a/src-web/components/core/PairEditor.tsx +++ b/src-web/components/core/PairEditor.tsx @@ -32,7 +32,6 @@ import { IconButton } from './IconButton'; import type { InputHandle, InputProps } from './Input'; import { Input } from './Input'; import { ensurePairId } from './PairEditor.util'; -import { PlainInput } from './PlainInput'; import type { RadioDropdownItem } from './RadioDropdown'; import { RadioDropdown } from './RadioDropdown'; @@ -80,7 +79,7 @@ export type PairWithId = Pair & { }; /** Max number of pairs to show before prompting the user to reveal the rest */ -const MAX_INITIAL_PAIRS = 50; +const MAX_INITIAL_PAIRS = 30; export function PairEditor({ allowFileValues, @@ -190,31 +189,21 @@ export function PairEditor({ [setPairsAndSave, pairs], ); - const handleFocusName = useCallback((pair: Pair) => { - setPairs((pairs) => { + const handleFocusName = useCallback( + (pair: Pair) => { const isLast = pair.id === pairs[pairs.length - 1]?.id; - if (isLast) { - const prevPair = pairs[pairs.length - 1]; - rowsRef.current[prevPair?.id ?? 'n/a']?.focusName(); - return [...pairs, emptyPair()]; - } else { - return pairs; - } - }); - }, []); + if (isLast) setPairs([...pairs, emptyPair()]); + }, + [pairs], + ); - const handleFocusValue = useCallback((pair: Pair) => { - setPairs((pairs) => { + const handleFocusValue = useCallback( + (pair: Pair) => { const isLast = pair.id === pairs[pairs.length - 1]?.id; - if (isLast) { - const prevPair = pairs[pairs.length - 1]; - rowsRef.current[prevPair?.id ?? 'n/a']?.focusValue(); - return [...pairs, emptyPair()]; - } else { - return pairs; - } - }); - }, []); + if (isLast) setPairs([...pairs, emptyPair()]); + }, + [pairs], + ); const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 6 } })); @@ -282,73 +271,86 @@ export function PairEditor({ '-mr-2 pr-2', // Pad to make room for the drag divider 'pt-0.5', + 'grid grid-rows-[auto_1fr]', )} > - - {pairs.map((p, i) => { - if (!showAll && i > MAX_INITIAL_PAIRS) return null; +
+ + {pairs.map((p, i) => { + if (!showAll && i > MAX_INITIAL_PAIRS) return null; - const isLast = i === pairs.length - 1; - return ( - - {hoveredIndex === i && } - - - ); - })} - {!showAll && pairs.length > MAX_INITIAL_PAIRS && ( - - )} - - {isDragging && ( - + const isLast = i === pairs.length - 1; + return ( + + {hoveredIndex === i && } + + + ); + })} + {!showAll && pairs.length > MAX_INITIAL_PAIRS && ( + )} - - + + {isDragging && ( + + )} + + +
+ +
{ + e.preventDefault(); + e.stopPropagation(); + }} + />
); } @@ -579,44 +581,29 @@ export function PairEditorRow({ 'gap-0.5 grid-cols-1 grid-rows-2', )} > - {isLast ? ( - // Use PlainInput for last ones because there's a unique bug where clicking below - // the Codemirror input focuses it. - - ) : ( - - )} +
{pair.isFile ? ( - ) : isLast ? ( - // Use PlainInput for last ones because there's a unique bug where clicking below - // the Codemirror input focuses it. - ) : pair.value.includes('\n') ? (