Delete paths associated with sketch when the sketch plane is deleted

This commit is contained in:
Frank Noirot
2025-02-12 16:32:53 -05:00
parent bf1a42f6c0
commit 3747db01b8

View File

@ -60,12 +60,11 @@ import { Models } from '@kittycad/lib'
import { ExtrudeFacePlane } from 'machines/modelingMachine'
import { Node } from 'wasm-lib/kcl/bindings/Node'
import { KclExpressionWithVariable } from 'lib/commandTypes'
import { Artifact, getPathsFromArtifact } from './std/artifactGraph'
import { Artifact, expandPath, expandPlane, getPathsFromArtifact } from './std/artifactGraph'
import { BodyItem } from 'wasm-lib/kcl/bindings/BodyItem'
import { findKwArg } from './util'
import { deleteEdgeTreatment } from './modifyAst/addEdgeTreatment'
import { kclManager } from 'lib/singletons'
import React from 'react'
import { engineCommandManager } from 'lib/singletons'
export function startSketchOnDefault(
node: Node<Program>,
@ -1386,6 +1385,21 @@ export async function deleteFromSelection(
({} as any)
): Promise<Node<Program> | Error> {
const astClone = structuredClone(ast)
console.log('deleting', selection, variables)
if (selection.artifact?.type === 'plane' && selection.artifact.pathIds.length) {
const plane = expandPlane(selection.artifact, engineCommandManager.artifactGraph)
console.log('plane expanded', plane)
for (const path of plane.paths.sort((a, b) => b.codeRef.range[0] - a.codeRef.range[0])) {
const varDec = getNodeFromPath<VariableDeclarator>(
ast,
path.codeRef.pathToNode,
'VariableDeclarator'
)
if (err(varDec)) return varDec
const bodyIndex = Number(varDec.shallowPath[1][0])
astClone.body.splice(bodyIndex, 1)
}
}
const varDec = getNodeFromPath<VariableDeclarator>(
ast,
selection?.codeRef?.pathToNode,
@ -1463,7 +1477,7 @@ export async function deleteFromSelection(
astClone.body.splice(expressionIndex, 1)
if (extrudeNameToDelete) {
await new Promise((resolve) => {
;(async () => {
; (async () => {
let currentVariableName = ''
const pathsDependingOnExtrude: Array<{
path: PathToNode
@ -1476,7 +1490,7 @@ export async function deleteFromSelection(
}
},
enter: (node, path) => {
;(async () => {
; (async () => {
if (node.type === 'VariableDeclaration') {
currentVariableName = node.declaration.id.name
}