Skip to content

The agent that grows with you

fix(desktop): preserve commas while editing list settings

Hukla94edc03bc2d8
diff --git a/apps/desktop/src/app/settings/config-field.test.ts b/apps/desktop/src/app/settings/config-field.test.ts
new file mode 100644
index 00000000000..9bdd475eb10
--- /dev/null
+++ b/apps/desktop/src/app/settings/config-field.test.ts
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest'
+
+import { parseListFieldDraft } from './config-field'
+
+describe('parseListFieldDraft', () => {
+ it('commits comma-separated list values after editing', () => {
+ expect(parseListFieldDraft('C:/gitLibraries, C:/gitProjects')).toEqual(['C:/gitLibraries', 'C:/gitProjects'])
+ })
+
+ it('trims entries and drops empty segments', () => {
+ expect(parseListFieldDraft(' one, , two, ')).toEqual(['one', 'two'])
+ })
+
+ it('allows an unfinished trailing comma to remain draft-only until commit', () => {
+ expect(parseListFieldDraft('first,')).toEqual(['first'])
+ })
+})
diff --git a/apps/desktop/src/app/settings/config-field.tsx b/apps/desktop/src/app/settings/config-field.tsx
index 66818117068..ec633f6ddea 100644
--- a/apps/desktop/src/app/settings/config-field.tsx
+++ b/apps/desktop/src/app/settings/config-field.tsx
@@ -1,4 +1,4 @@
-import type { ReactNode } from 'react'
+import { type ReactNode, useEffect, useRef, useState } from 'react'
import { Input } from '@/components/ui/input'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
@@ -15,6 +15,13 @@ import { fieldCopyForSchemaKey } from './field-copy'
import { ListRow, ToggleRow } from './primitives'
import { SearchableSelect } from './searchable-select'
+export function parseListFieldDraft(raw: string): string[] {
+ return raw
+ .split(',')
+ .map(item => item.trim())
+ .filter(Boolean)
+}
+
/**
* One generic config row: label + description resolved from the i18n field
* copy (falling back to the schema description), and a control picked from the
@@ -200,21 +207,7 @@ export function ConfigField({
}
if (schema.type === 'list') {
- return row(
- <Input
- className={CONTROL_TEXT}
- onChange={e =>
- onChange(
- e.target.value
- .split(',')
- .map(s => s.trim())
- .filter(Boolean)
- )
- }
- placeholder={c.commaSeparated}
- value={Array.isArray(value) ? value.join(', ') : String(value ?? '')}
- />
- )
+ return row(<ListField onChange={onChange} placeholder={c.commaSeparated} value={value} />)
}
if (typeof value === 'object' && value !== null) {
@@ -255,3 +248,50 @@ export function ConfigField({
/>
)
}
+
+function ListField({
+ value,
+ onChange,
+ placeholder
+}: {
+ value: unknown
+ onChange: (value: unknown) => void
+ placeholder: string
+}) {
+ const normalizedValue = Array.isArray(value) ? value.join(', ') : String(value ?? '')
+ const [draft, setDraft] = useState(normalizedValue)
+ const focusedRef = useRef(false)
+
+ useEffect(() => {
+ if (!focusedRef.current) {
+ setDraft(normalizedValue)
+ }
+ }, [normalizedValue])
+
+ const commitDraft = () => {
+ const parsed = parseListFieldDraft(draft)
+ setDraft(parsed.join(', '))
+ onChange(parsed)
+ }
+
+ return (
+ <Input
+ className={CONTROL_TEXT}
+ onBlur={() => {
+ focusedRef.current = false
+ commitDraft()
+ }}
+ onChange={e => setDraft(e.target.value)}
+ onFocus={() => {
+ focusedRef.current = true
+ }}
+ onKeyDown={e => {
+ if (e.key === 'Enter') {
+ e.currentTarget.blur()
+ }
+ }}
+ placeholder={placeholder}
+ value={draft}
+ />
+ )
+}
diff --git a/apps/desktop/src/app/settings/searchable-select.test.tsx b/apps/desktop/src/app/settings/searchable-select.test.tsx
index 68546bf0b0f..e28aeabf82e 100644
--- a/apps/desktop/src/app/settings/searchable-select.test.tsx
+++ b/apps/desktop/src/app/settings/searchable-select.test.tsx
@@ -134,3 +134,41 @@ describe('ConfigField searchable routing', () => {
expect(onChange).toHaveBeenCalledWith('')
})
})
+
+describe('ConfigField list editing', () => {
+ const listSchema: ConfigFieldSchema = { type: 'list' }
+
+ it('keeps unfinished comma input as a draft until blur commits it', () => {
+ const onChange = vi.fn()
+
+ render(<ConfigField onChange={onChange} schema={listSchema} schemaKey="test.list" value={['first']} />)
+
+ const input = screen.getByRole('textbox') as HTMLInputElement
+ fireEvent.focus(input)
+ fireEvent.change(input, { target: { value: 'first,' } })
+
+ expect(input.value).toBe('first,')
+ expect(onChange).not.toHaveBeenCalled()
+
+ fireEvent.blur(input)
+
+ expect(onChange).toHaveBeenCalledTimes(1)
+ expect(onChange).toHaveBeenCalledWith(['first'])
+ expect(input.value).toBe('first')
+ })
+
+ it('commits exactly once when Enter blurs the list field', () => {
+ const onChange = vi.fn()
+
+ render(<ConfigField onChange={onChange} schema={listSchema} schemaKey="test.list" value={['first']} />)
+
+ const input = screen.getByRole('textbox') as HTMLInputElement
+ fireEvent.focus(input)
+ fireEvent.change(input, { target: { value: 'first, second' } })
+ fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' })
+
+ expect(onChange).toHaveBeenCalledTimes(1)
+ expect(onChange).toHaveBeenCalledWith(['first', 'second'])
+ expect(input.value).toBe('first, second')
+ })
+})