add multiple selections support for focusPath (#3944)
This commit is contained in:
@ -416,7 +416,7 @@ export class KclManager {
|
|||||||
ast: Program,
|
ast: Program,
|
||||||
execute: boolean,
|
execute: boolean,
|
||||||
optionalParams?: {
|
optionalParams?: {
|
||||||
focusPath?: PathToNode
|
focusPath?: Array<PathToNode>
|
||||||
zoomToFit?: boolean
|
zoomToFit?: boolean
|
||||||
zoomOnRangeAndType?: {
|
zoomOnRangeAndType?: {
|
||||||
range: SourceRange
|
range: SourceRange
|
||||||
@ -435,27 +435,34 @@ export class KclManager {
|
|||||||
let returnVal: Selections | undefined = undefined
|
let returnVal: Selections | undefined = undefined
|
||||||
|
|
||||||
if (optionalParams?.focusPath) {
|
if (optionalParams?.focusPath) {
|
||||||
const _node1 = getNodeFromPath<any>(
|
|
||||||
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 = {
|
returnVal = {
|
||||||
codeBasedSelections: [
|
codeBasedSelections: [],
|
||||||
{
|
otherSelections: [],
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const path of optionalParams.focusPath) {
|
||||||
|
const getNodeFromPathResult = getNodeFromPath<any>(
|
||||||
|
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',
|
type: 'default',
|
||||||
range: [start, end],
|
range: [start, end],
|
||||||
},
|
})
|
||||||
],
|
}
|
||||||
otherSelections: [],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ export function modifyAstWithFilletAndTag(
|
|||||||
ast: Program,
|
ast: Program,
|
||||||
selection: Selections,
|
selection: Selections,
|
||||||
radius: KclCommandValue
|
radius: KclCommandValue
|
||||||
): { modifiedAst: Program; pathToFilletNode: PathToNode } | Error {
|
): { modifiedAst: Program; pathToFilletNode: Array<PathToNode> } | Error {
|
||||||
const astResult = insertRadiusIntoAst(ast, radius)
|
const astResult = insertRadiusIntoAst(ast, radius)
|
||||||
if (err(astResult)) return astResult
|
if (err(astResult)) return astResult
|
||||||
|
|
||||||
@ -73,7 +73,8 @@ export function modifyAstWithFilletAndTag(
|
|||||||
const artifactGraph = engineCommandManager.artifactGraph
|
const artifactGraph = engineCommandManager.artifactGraph
|
||||||
|
|
||||||
let clonedAst = structuredClone(ast)
|
let clonedAst = structuredClone(ast)
|
||||||
let lastPathToFilletNode: PathToNode = []
|
const clonedAstForGetExtrude = structuredClone(ast)
|
||||||
|
let pathToFilletNodes: Array<PathToNode> = []
|
||||||
|
|
||||||
for (const selectionRange of selection.codeBasedSelections) {
|
for (const selectionRange of selection.codeBasedSelections) {
|
||||||
const singleSelection = {
|
const singleSelection = {
|
||||||
@ -82,7 +83,7 @@ export function modifyAstWithFilletAndTag(
|
|||||||
}
|
}
|
||||||
const getPathToExtrudeForSegmentSelectionResult =
|
const getPathToExtrudeForSegmentSelectionResult =
|
||||||
getPathToExtrudeForSegmentSelection(
|
getPathToExtrudeForSegmentSelection(
|
||||||
clonedAst,
|
clonedAstForGetExtrude,
|
||||||
singleSelection,
|
singleSelection,
|
||||||
programMemory,
|
programMemory,
|
||||||
artifactGraph
|
artifactGraph
|
||||||
@ -101,9 +102,9 @@ export function modifyAstWithFilletAndTag(
|
|||||||
if (trap(addFilletResult)) return addFilletResult
|
if (trap(addFilletResult)) return addFilletResult
|
||||||
const { modifiedAst, pathToFilletNode } = addFilletResult
|
const { modifiedAst, pathToFilletNode } = addFilletResult
|
||||||
clonedAst = modifiedAst
|
clonedAst = modifiedAst
|
||||||
lastPathToFilletNode = pathToFilletNode
|
pathToFilletNodes.push(pathToFilletNode)
|
||||||
}
|
}
|
||||||
return { modifiedAst: clonedAst, pathToFilletNode: lastPathToFilletNode }
|
return { modifiedAst: clonedAst, pathToFilletNode: pathToFilletNodes }
|
||||||
}
|
}
|
||||||
|
|
||||||
function insertRadiusIntoAst(
|
function insertRadiusIntoAst(
|
||||||
@ -166,7 +167,7 @@ export function getPathToExtrudeForSegmentSelection(
|
|||||||
|
|
||||||
async function updateAstAndFocus(
|
async function updateAstAndFocus(
|
||||||
modifiedAst: Program,
|
modifiedAst: Program,
|
||||||
pathToFilletNode: PathToNode
|
pathToFilletNode: Array<PathToNode>
|
||||||
) {
|
) {
|
||||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||||
focusPath: pathToFilletNode,
|
focusPath: pathToFilletNode,
|
||||||
|
@ -555,7 +555,7 @@ export const modelingMachine = setup({
|
|||||||
|
|
||||||
store.videoElement?.pause()
|
store.videoElement?.pause()
|
||||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||||
focusPath: pathToExtrudeArg,
|
focusPath: [pathToExtrudeArg],
|
||||||
zoomToFit: true,
|
zoomToFit: true,
|
||||||
zoomOnRangeAndType: {
|
zoomOnRangeAndType: {
|
||||||
range: selection.codeBasedSelections[0].range,
|
range: selection.codeBasedSelections[0].range,
|
||||||
@ -602,7 +602,7 @@ export const modelingMachine = setup({
|
|||||||
|
|
||||||
store.videoElement?.pause()
|
store.videoElement?.pause()
|
||||||
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
const updatedAst = await kclManager.updateAst(modifiedAst, true, {
|
||||||
focusPath: pathToRevolveArg,
|
focusPath: [pathToRevolveArg],
|
||||||
zoomToFit: true,
|
zoomToFit: true,
|
||||||
zoomOnRangeAndType: {
|
zoomOnRangeAndType: {
|
||||||
range: selection.codeBasedSelections[0].range,
|
range: selection.codeBasedSelections[0].range,
|
||||||
|
Reference in New Issue
Block a user