diff --git a/src/lang/KclSingleton.ts b/src/lang/KclSingleton.ts index ec8f5a28a..57c7ee613 100644 --- a/src/lang/KclSingleton.ts +++ b/src/lang/KclSingleton.ts @@ -416,7 +416,7 @@ export class KclManager { ast: Program, execute: boolean, optionalParams?: { - focusPath?: PathToNode + focusPath?: Array zoomToFit?: boolean zoomOnRangeAndType?: { range: SourceRange @@ -435,27 +435,34 @@ export class KclManager { let returnVal: Selections | undefined = undefined if (optionalParams?.focusPath) { - const _node1 = getNodeFromPath( - astWithUpdatedSource, - optionalParams?.focusPath - ) - if (err(_node1)) return Promise.reject(_node1) - const { node } = _node1 - - const { start, end } = node - if (!start || !end) - return { - selections: undefined, - newAst: astWithUpdatedSource, - } returnVal = { - codeBasedSelections: [ - { + codeBasedSelections: [], + otherSelections: [], + } + + for (const path of optionalParams.focusPath) { + const getNodeFromPathResult = getNodeFromPath( + astWithUpdatedSource, + path + ) + if (err(getNodeFromPathResult)) + return Promise.reject(getNodeFromPathResult) + const { node } = getNodeFromPathResult + + const { start, end } = node + + if (!start || !end) + return { + selections: undefined, + newAst: astWithUpdatedSource, + } + + if (start && end) { + returnVal.codeBasedSelections.push({ type: 'default', range: [start, end], - }, - ], - otherSelections: [], + }) + } } } diff --git a/src/lang/modifyAst/addFillet.ts b/src/lang/modifyAst/addFillet.ts index bf379c8ed..a2495c319 100644 --- a/src/lang/modifyAst/addFillet.ts +++ b/src/lang/modifyAst/addFillet.ts @@ -65,7 +65,7 @@ export function modifyAstWithFilletAndTag( ast: Program, selection: Selections, radius: KclCommandValue -): { modifiedAst: Program; pathToFilletNode: PathToNode } | Error { +): { modifiedAst: Program; pathToFilletNode: Array } | Error { const astResult = insertRadiusIntoAst(ast, radius) if (err(astResult)) return astResult @@ -73,7 +73,8 @@ export function modifyAstWithFilletAndTag( const artifactGraph = engineCommandManager.artifactGraph let clonedAst = structuredClone(ast) - let lastPathToFilletNode: PathToNode = [] + const clonedAstForGetExtrude = structuredClone(ast) + let pathToFilletNodes: Array = [] for (const selectionRange of selection.codeBasedSelections) { const singleSelection = { @@ -82,7 +83,7 @@ export function modifyAstWithFilletAndTag( } const getPathToExtrudeForSegmentSelectionResult = getPathToExtrudeForSegmentSelection( - clonedAst, + clonedAstForGetExtrude, singleSelection, programMemory, artifactGraph @@ -101,9 +102,9 @@ export function modifyAstWithFilletAndTag( if (trap(addFilletResult)) return addFilletResult const { modifiedAst, pathToFilletNode } = addFilletResult clonedAst = modifiedAst - lastPathToFilletNode = pathToFilletNode + pathToFilletNodes.push(pathToFilletNode) } - return { modifiedAst: clonedAst, pathToFilletNode: lastPathToFilletNode } + return { modifiedAst: clonedAst, pathToFilletNode: pathToFilletNodes } } function insertRadiusIntoAst( @@ -166,7 +167,7 @@ export function getPathToExtrudeForSegmentSelection( async function updateAstAndFocus( modifiedAst: Program, - pathToFilletNode: PathToNode + pathToFilletNode: Array ) { const updatedAst = await kclManager.updateAst(modifiedAst, true, { focusPath: pathToFilletNode, diff --git a/src/machines/modelingMachine.ts b/src/machines/modelingMachine.ts index 84601a27a..ca8c64a96 100644 --- a/src/machines/modelingMachine.ts +++ b/src/machines/modelingMachine.ts @@ -571,7 +571,7 @@ export const modelingMachine = setup({ store.videoElement?.pause() const updatedAst = await kclManager.updateAst(modifiedAst, true, { - focusPath: pathToExtrudeArg, + focusPath: [pathToExtrudeArg], zoomToFit: true, zoomOnRangeAndType: { range: selection.codeBasedSelections[0].range, @@ -618,7 +618,7 @@ export const modelingMachine = setup({ store.videoElement?.pause() const updatedAst = await kclManager.updateAst(modifiedAst, true, { - focusPath: pathToRevolveArg, + focusPath: [pathToRevolveArg], zoomToFit: true, zoomOnRangeAndType: { range: selection.codeBasedSelections[0].range,