diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 4ad56d2f..417afb9c 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -524,12 +524,37 @@ function ListBody({ type: outerType, node, makeEdit, ctx }: ListBodyProps) { return <>> } const type = (node.typeDef?.kind === 'list' || node.typeDef?.kind === 'byte_array' || node.typeDef?.kind === 'int_array' || node.typeDef?.kind === 'long_array') ? node.typeDef : outerType + const fixedRange = type.lengthRange?.min !== undefined && type.lengthRange.min === type.lengthRange.max + const onRemoveItem = useCallback((index: number) => { makeEdit(() => { node.children.splice(index, 1) return node }) }, [makeEdit, node]) + + const onMoveUp = useCallback((index: number) => { + if (node.children.length <= 1 || index <= 0) { + return + } + makeEdit(() => { + const moved = node.children.splice(index, 1) + node.children.splice(index - 1, 0, ...moved) + return node + }) + }, [makeEdit]) + + const onMoveDown = useCallback((index: number) => { + if (node.children.length <= 1 || index >= node.children.length - 1) { + return + } + makeEdit(() => { + const moved = node.children.splice(index, 1) + node.children.splice(index + 1, 0, ...moved) + return node + }) + }, [makeEdit]) + return <> {node.children.map((item, index) => { const child = item.value @@ -546,20 +571,24 @@ function ListBody({ type: outerType, node, makeEdit, ctx }: ListBodyProps) { return node }) } + const canMoveUp = node.children.length > 1 && index > 0 + const canMoveDown = node.children.length > 1 && index < (node.children.length - 1) return