From 0d6419aa161d5e3c55921b7da9ac45a24e230ecc Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 4 Jun 2026 23:31:47 -0400 Subject: [PATCH] feat(settings): replace config card grid with single-select dropdown (#251) * feat(settings): replace config card grid with single-select dropdown Redesign the OpenCode config list from a 2-column card grid to a single-select dropdown with adjacent action buttons (download, edit, set-current, delete) and the New Config button in the same row. Remove stale New Config buttons from ServerHealthStatus and the OpenCodeConfigManager health card section. * feat(settings): add find-in-text search for config editor --- .../settings/OpenCodeConfigEditor.tsx | 132 +++++++++++-- .../settings/OpenCodeConfigManager.tsx | 178 ++++++++++-------- .../settings/ServerHealthStatus.tsx | 12 +- frontend/src/lib/useFindInText.test.ts | 58 ++++++ frontend/src/lib/useFindInText.ts | 75 ++++++++ 5 files changed, 360 insertions(+), 95 deletions(-) create mode 100644 frontend/src/lib/useFindInText.test.ts create mode 100644 frontend/src/lib/useFindInText.ts diff --git a/frontend/src/components/settings/OpenCodeConfigEditor.tsx b/frontend/src/components/settings/OpenCodeConfigEditor.tsx index 9b4543bb..6e765bff 100644 --- a/frontend/src/components/settings/OpenCodeConfigEditor.tsx +++ b/frontend/src/components/settings/OpenCodeConfigEditor.tsx @@ -1,8 +1,10 @@ import { useState, useRef, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Textarea } from '@/components/ui/textarea' -import { Loader2 } from 'lucide-react' +import { Loader2, Search, ChevronUp, ChevronDown } from 'lucide-react' import { Dialog, DialogContent, DialogHeader, DialogFooter, DialogTitle } from '@/components/ui/dialog' +import { Input } from '@/components/ui/input' +import { useFindInText } from '@/lib/useFindInText' import type { OpenCodeConfig } from '@/api/types/settings' import { parseJsonc } from '@/lib/jsonc' import { FetchError } from '@/api/fetchWrapper' @@ -34,6 +36,8 @@ export function OpenCodeConfigEditor({ const [validationIssues, setValidationIssues] = useState([]) const [removedFields, setRemovedFields] = useState([]) const editTextareaRef = useRef(null) + const backdropRef = useRef(null) + const { query, setQuery, matches, currentMatchIndex, hasMatches, next, prev } = useFindInText(editConfigContent) useEffect(() => { if (config && isOpen) { @@ -51,6 +55,63 @@ export function OpenCodeConfigEditor({ } }, [isOpen]) + useEffect(() => { + const textarea = editTextareaRef.current + if (!textarea || matches.length === 0) return + const match = matches[currentMatchIndex] + if (match) { + const textBefore = editConfigContent.substring(0, match.startIndex) + const lineNumber = textBefore.split('\n').length + const lineHeight = textarea.scrollHeight / textarea.value.split('\n').length + textarea.scrollTop = lineHeight * (lineNumber - 1) - textarea.clientHeight / 2 + lineHeight / 2 + syncBackdropScroll() + } + }, [currentMatchIndex, matches, editConfigContent]) + + const syncBackdropScroll = () => { + const textarea = editTextareaRef.current + const backdrop = backdropRef.current + if (textarea && backdrop) { + backdrop.scrollTop = textarea.scrollTop + backdrop.scrollLeft = textarea.scrollLeft + } + } + + const handleFindKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + e.preventDefault() + if (e.shiftKey) prev() + else next() + } + } + + const renderHighlightedContent = () => { + if (matches.length === 0) { + return editConfigContent + } + const segments: React.ReactNode[] = [] + let lastIndex = 0 + matches.forEach((match, index) => { + if (match.startIndex > lastIndex) { + segments.push(editConfigContent.substring(lastIndex, match.startIndex)) + } + const isCurrent = index === currentMatchIndex + segments.push( + + {editConfigContent.substring(match.startIndex, match.endIndex)} + + ) + lastIndex = match.endIndex + }) + if (lastIndex < editConfigContent.length) { + segments.push(editConfigContent.substring(lastIndex)) + } + return segments + } + const resetErrors = () => { setEditError('') setEditErrorLine(null) @@ -131,17 +192,66 @@ export function OpenCodeConfigEditor({ +
+
+ + setQuery(e.target.value)} + onKeyDown={handleFindKeyDown} + placeholder="Find in config..." + className="pl-9 h-9 text-[16px] sm:text-xs md:text-sm" + autoComplete="off" + name="config-find" + /> +
+ {query && ( + + {hasMatches + ? `${currentMatchIndex + 1} of ${matches.length}` + : '0 matches'} + + )} + + +
+
-