Fix bug with undo startSketchOn
removing existing sketch (#6834)
* Fix bug with `undo startSketchOn` removing existing sketch Fixes #6822, I believe. in this case the `variableName` was not being marked as in-use, so I just logged out the AST and made sure this case was covered. @Irev-Dev this is probably worth a check from you. * Add a regression test It's an E2E test because I'm being lazy, but it should probably be an XState unit test at some point. * check what's checked --------- Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit is contained in:
@ -841,6 +841,40 @@ washer = extrude(washerSketch, length = thicknessMax)`
|
||||
await editor.expectEditor.toContain('@settings(defaultLengthUnit = yd)')
|
||||
})
|
||||
})
|
||||
|
||||
test('Exiting existing sketch without editing should not delete it', async ({
|
||||
page,
|
||||
editor,
|
||||
homePage,
|
||||
context,
|
||||
toolbar,
|
||||
scene,
|
||||
cmdBar,
|
||||
}) => {
|
||||
await context.folderSetupFn(async (dir) => {
|
||||
const testDir = path.join(dir, 'test')
|
||||
await fsp.mkdir(testDir, { recursive: true })
|
||||
await fsp.writeFile(
|
||||
path.join(testDir, 'main.kcl'),
|
||||
`s1 = startSketchOn(XY)
|
||||
|> startProfile(at = [0, 25])
|
||||
|> xLine(endAbsolute = -15 + 1.5)
|
||||
s2 = startSketchOn(XY)
|
||||
|> startProfile(at = [25, 0])
|
||||
|> yLine(endAbsolute = -15 + 1.5)`,
|
||||
'utf-8'
|
||||
)
|
||||
})
|
||||
|
||||
await homePage.openProject('test')
|
||||
await scene.settled(cmdBar)
|
||||
await toolbar.waitForFeatureTreeToBeBuilt()
|
||||
await toolbar.editSketch(1)
|
||||
await page.waitForTimeout(1000) // Just hang out for a second
|
||||
await toolbar.exitSketch()
|
||||
|
||||
await editor.expectEditor.toContain('s2 = startSketchOn(XY)')
|
||||
})
|
||||
})
|
||||
|
||||
async function clickExportButton(page: Page) {
|
||||
|
@ -751,13 +751,22 @@ export const ModelingMachineProvider = ({
|
||||
if (err(varDec)) return reject(new Error('No varDec'))
|
||||
const variableName = varDec.node.declaration.id.name
|
||||
let isIdentifierUsed = false
|
||||
traverse(newAst, {
|
||||
enter: (node) => {
|
||||
if (node.type === 'Name' && node.name.name === variableName) {
|
||||
isIdentifierUsed = true
|
||||
}
|
||||
},
|
||||
})
|
||||
const isInitAPipe =
|
||||
varDec.node.declaration.init.type === 'PipeExpression'
|
||||
if (isInitAPipe) {
|
||||
isIdentifierUsed = true
|
||||
} else {
|
||||
traverse(newAst, {
|
||||
enter: (node) => {
|
||||
if (
|
||||
node.type === 'Name' &&
|
||||
node.name.name === variableName
|
||||
) {
|
||||
isIdentifierUsed = true
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
if (isIdentifierUsed) return
|
||||
|
||||
// remove body item at varDecIndex
|
||||
|
Reference in New Issue
Block a user