Clean up 'prompt user for info' modals (#58)

This commit is contained in:
Kurt Hutten
2023-03-13 09:22:05 +11:00
committed by GitHub
parent eebddb0ce2
commit 1de21b8bdd
6 changed files with 491 additions and 309 deletions

View File

@ -12,7 +12,7 @@ import {
getTransformInfos,
transformAstSketchLines,
} from '../../lang/std/sketchcombos'
import { SetAngleLengthModal } from '../SetAngleModal'
import { SetAngleLengthModal } from '../SetAngleLengthModal'
import {
createIdentifier,
createVariableDeclaration,
@ -69,18 +69,12 @@ export const SetAngleLength = ({
programMemory,
referenceSegName: '',
})
const availableVarInfo = findAllPreviousVariables(
modifiedAst,
programMemory,
selectionRanges[0]
)
try {
const { valueNode, variableName } = await getModalInfo({
value: valueUsedInTransform,
prevVariables: availableVarInfo.variables,
valueName: angleOrLength === 'setAngle' ? 'angle' : 'length',
} as any)
const { valueNode, variableName, newVariableInsertIndex } =
await getModalInfo({
value: valueUsedInTransform,
valueName: angleOrLength === 'setAngle' ? 'angle' : 'length',
} as any)
const { modifiedAst: _modifiedAst } = transformAstSketchLines({
ast: JSON.parse(JSON.stringify(ast)),
@ -95,7 +89,7 @@ export const SetAngleLength = ({
if (variableName) {
const newBody = [..._modifiedAst.body]
newBody.splice(
availableVarInfo.insertIndex,
newVariableInsertIndex,
0,
createVariableDeclaration(variableName, valueNode)
)