mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
* 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
76 lines
1.8 KiB
TypeScript
76 lines
1.8 KiB
TypeScript
import { useState, useMemo, useCallback } from 'react'
|
|
|
|
interface FindMatch {
|
|
startIndex: number
|
|
endIndex: number
|
|
}
|
|
|
|
interface UseFindInTextReturn {
|
|
query: string
|
|
setQuery: (q: string) => void
|
|
matches: FindMatch[]
|
|
currentMatchIndex: number
|
|
hasMatches: boolean
|
|
next: () => void
|
|
prev: () => void
|
|
clear: () => void
|
|
}
|
|
|
|
export function useFindInText(text: string): UseFindInTextReturn {
|
|
const [query, setQueryState] = useState('')
|
|
const [currentMatchIndex, setCurrentMatchIndex] = useState(0)
|
|
|
|
const matches = useMemo(() => {
|
|
if (!query.trim()) return []
|
|
const results: FindMatch[] = []
|
|
const lowerText = text.toLowerCase()
|
|
const lowerQuery = query.toLowerCase()
|
|
let idx = 0
|
|
while (true) {
|
|
idx = lowerText.indexOf(lowerQuery, idx)
|
|
if (idx === -1) break
|
|
results.push({ startIndex: idx, endIndex: idx + query.length })
|
|
idx += query.length
|
|
}
|
|
return results
|
|
}, [text, query])
|
|
|
|
const safeIndex = useMemo(() => {
|
|
if (matches.length === 0) return 0
|
|
return Math.max(0, Math.min(currentMatchIndex, matches.length - 1))
|
|
}, [currentMatchIndex, matches.length])
|
|
|
|
const next = useCallback(() => {
|
|
if (matches.length > 0) {
|
|
setCurrentMatchIndex(prev => (prev + 1) % matches.length)
|
|
}
|
|
}, [matches.length])
|
|
|
|
const prev = useCallback(() => {
|
|
if (matches.length > 0) {
|
|
setCurrentMatchIndex(prev => (prev - 1 + matches.length) % matches.length)
|
|
}
|
|
}, [matches.length])
|
|
|
|
const clear = useCallback(() => {
|
|
setQueryState('')
|
|
setCurrentMatchIndex(0)
|
|
}, [])
|
|
|
|
const setQuery = useCallback((q: string) => {
|
|
setQueryState(q)
|
|
setCurrentMatchIndex(0)
|
|
}, [])
|
|
|
|
return {
|
|
query,
|
|
setQuery,
|
|
matches,
|
|
currentMatchIndex: safeIndex,
|
|
hasMatches: matches.length > 0,
|
|
next,
|
|
prev,
|
|
clear,
|
|
}
|
|
}
|