From 18dd627ad8ae01a3de2b6eb28a1467a47e5e14e4 Mon Sep 17 00:00:00 2001 From: Misode Date: Thu, 24 Oct 2024 23:32:56 +0200 Subject: [PATCH] Fix issue with setting strings to unset --- .../components/generator/McdocRenderer.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 07e11dc8..7cd1522d 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -88,12 +88,20 @@ function StringHead({ type, optional, node, makeEdit, ctx }: StringHeadProps) { const value = JsonStringNode.is(node) ? node.value : undefined + const idAttribute = type.attributes?.find(a => a.name === 'id')?.value + const idRegistry = idAttribute?.kind === 'literal' && idAttribute.value.kind === 'string' + ? idAttribute.value.value + : idAttribute?.kind === 'tree' && idAttribute.values.registry?.kind === 'literal' && idAttribute.values.registry?.value.kind === 'string' + ? idAttribute.values.registry?.value.value + : undefined + const isSelect = idRegistry && selectRegistries.has(idRegistry) + const onChangeValue = useCallback((newValue: string) => { if (value === newValue) { return } makeEdit((range) => { - if (newValue.length === 0 && optional) { + if ((newValue.length === 0 && optional) || (isSelect && newValue === SPECIAL_UNSET)) { return undefined } return { @@ -104,15 +112,7 @@ function StringHead({ type, optional, node, makeEdit, ctx }: StringHeadProps) { valueMap: [{ inner: core.Range.create(0), outer: core.Range.create(range.start) }], } }) - }, [optional, node, makeEdit]) - - const idAttribute = type.attributes?.find(a => a.name === 'id')?.value - const idRegistry = idAttribute?.kind === 'literal' && idAttribute.value.kind === 'string' - ? idAttribute.value.value - : idAttribute?.kind === 'tree' && idAttribute.values.registry?.kind === 'literal' && idAttribute.values.registry?.value.kind === 'string' - ? idAttribute.values.registry?.value.value - : undefined - const isSelect = idRegistry && selectRegistries.has(idRegistry) + }, [optional, node, makeEdit, isSelect]) const completions = useMemo(() => { return getValues(type, { ...ctx, offset: node?.range.start ?? 0 }) @@ -308,7 +308,7 @@ function UnionHead({ type, optional, node, makeEdit, ctx }: UnionHeadProps) { )} - {selectedType && } + {selectedType && } }