add multiple selections support for focusPath (#3944)

This commit is contained in:
max
2024-09-23 08:07:31 +02:00
committed by GitHub
parent 619b059ae1
commit 7848d63177
3 changed files with 35 additions and 27 deletions

View File

@ -416,7 +416,7 @@ export class KclManager {
ast: Program,
execute: boolean,
optionalParams?: {
focusPath?: PathToNode
focusPath?: Array<PathToNode>
zoomToFit?: boolean
zoomOnRangeAndType?: {
range: SourceRange
@ -435,27 +435,34 @@ export class KclManager {
let returnVal: Selections | undefined = undefined
if (optionalParams?.focusPath) {
const _node1 = getNodeFromPath<any>(
returnVal = {
codeBasedSelections: [],
otherSelections: [],
}
for (const path of optionalParams.focusPath) {
const getNodeFromPathResult = getNodeFromPath<any>(
astWithUpdatedSource,
optionalParams?.focusPath
path
)
if (err(_node1)) return Promise.reject(_node1)
const { node } = _node1
if (err(getNodeFromPathResult))
return Promise.reject(getNodeFromPathResult)
const { node } = getNodeFromPathResult
const { start, end } = node
if (!start || !end)
return {
selections: undefined,
newAst: astWithUpdatedSource,
}
returnVal = {
codeBasedSelections: [
{
if (start && end) {
returnVal.codeBasedSelections.push({
type: 'default',
range: [start, end],
},
],
otherSelections: [],
})
}
}
}

View File

@ -65,7 +65,7 @@ export function modifyAstWithFilletAndTag(
ast: Program,
selection: Selections,
radius: KclCommandValue
): { modifiedAst: Program; pathToFilletNode: PathToNode } | Error {
): { modifiedAst: Program; pathToFilletNode: Array<PathToNode> } | 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<PathToNode> = []
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<PathToNode>
) {
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
focusPath: pathToFilletNode,

View File

@ -555,7 +555,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,
@ -602,7 +602,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,