fix(editor): plurals, trimmed names, default tab, parent drawing confirmation

This commit is contained in:
bchanot committed 2026-11-04 19:40:43 +01:00
1 parent b42c6ae844
commit be4f468790
35 files changed
+385 -63

No files matched your search

@@ -15,6 +15,8 @@ export interface TextFieldProps {
readOnly?: boolean
multiline?: boolean
maxLength?: number
/** Opt-in for names and simple labels: the committed value loses its edge spaces. */
trim?: boolean
hint?: string
/** The refusal phrased by the caller, shown next to the control. */
error?: string
@@ -46,6 +48,7 @@ function EditableText({
onCommit,
multiline,
maxLength,
trim,
hint,
error,
}: TextFieldProps) {
@@ -56,20 +59,23 @@ function EditableText({
setSeen(value)
setDraft(value)
}
const latest = useRef({ draft, value, onCommit })
const latest = useRef({ draft, value, onCommit, trim })
useEffect(() => {
latest.current = { draft, value, onCommit }
latest.current = { draft, value, onCommit, trim }
})
useEffect(
() => () => {
const pending = latest.current
if (pending.draft !== pending.value) pending.onCommit(pending.draft)
const next = pending.trim ? pending.draft.trim() : pending.draft
if (next !== pending.value) pending.onCommit(next)
},
[],
)
const commit = () => {
if (draft !== value) onCommit(draft)
const next = trim ? draft.trim() : draft
if (next !== draft) setDraft(next)
if (next !== value) onCommit(next)
}
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter' && !event.nativeEvent.isComposing) commit()