Skip to content

Commit ac3cfc3

Browse files
fix: allow editing in config editor without clearing search first (#265)
1 parent bcabcc1 commit ac3cfc3

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎frontend/src/components/settings/OpenCodeConfigEditor.tsx‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export function OpenCodeConfigEditor({
3535
const [editErrorLine, setEditErrorLine] = useState<number | null>(null)
3636
const [validationIssues, setValidationIssues] = useState<ValidationIssue[]>([])
3737
const [removedFields, setRemovedFields] = useState<string[]>([])
38+
const [isTextareaFocused, setIsTextareaFocused] = useState(false)
3839
const editTextareaRef = useRef<HTMLTextAreaElement>(null)
3940
const backdropRef = useRef<HTMLDivElement>(null)
4041
const { query, setQuery, matches, currentMatchIndex, hasMatches, next, prev } = useFindInText(editConfigContent)
@@ -85,8 +86,8 @@ export function OpenCodeConfigEditor({
8586
}
8687
}
8788

88-
const renderHighlightedContent = () => {
89-
if (matches.length === 0) {
89+
const renderHighlightedContent = (focused: boolean) => {
90+
if (matches.length === 0 || focused) {
9091
return editConfigContent
9192
}
9293
const segments: React.ReactNode[] = []
@@ -235,9 +236,9 @@ export function OpenCodeConfigEditor({
235236
<div
236237
ref={backdropRef}
237238
aria-hidden="true"
238-
className={`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap break-words font-mono text-[16px] sm:text-xs md:text-sm px-3 py-2 border border-transparent rounded-none sm:rounded-md ${hasMatches ? 'text-foreground' : 'text-transparent'}`}
239+
className={`pointer-events-none absolute inset-0 overflow-hidden whitespace-pre-wrap break-words font-mono text-[16px] sm:text-xs md:text-sm px-3 py-2 border border-transparent rounded-none sm:rounded-md ${hasMatches && !isTextareaFocused ? 'text-foreground' : 'text-transparent'}`}
239240
>
240-
{renderHighlightedContent()}
241+
{renderHighlightedContent(isTextareaFocused)}
241242
</div>
242243
<Textarea
243244
id="edit-config-content"
@@ -248,8 +249,10 @@ export function OpenCodeConfigEditor({
248249
resetErrors()
249250
}}
250251
onScroll={syncBackdropScroll}
252+
onFocus={() => setIsTextareaFocused(true)}
253+
onBlur={() => setIsTextareaFocused(false)}
251254
spellCheck={false}
252-
className={`relative bg-transparent font-mono text-[16px] sm:text-xs md:text-sm resize-none h-full w-full rounded-none sm:rounded-md ${hasMatches ? 'text-transparent caret-foreground' : ''} ${editErrorLine ? 'error-highlight' : ''}`}
255+
className={`relative bg-transparent font-mono text-[16px] sm:text-xs md:text-sm resize-none h-full w-full rounded-none sm:rounded-md ${hasMatches && !isTextareaFocused ? 'text-transparent caret-foreground' : ''} ${editErrorLine ? 'error-highlight' : ''}`}
253256
/>
254257
</div>
255258
{editError && (

0 commit comments

Comments
 (0)