@ -29,6 +29,7 @@ import {
|
||||
import { Mesh, Object3D, Object3DEventMap } from 'three'
|
||||
import { AXIS_GROUP, X_AXIS } from 'clientSideScene/sceneInfra'
|
||||
import { PathToNodeMap } from 'lang/std/sketchcombos'
|
||||
import { err } from 'lib/trap'
|
||||
|
||||
export const X_AXIS_UUID = 'ad792545-7fd3-482a-a602-a93924e3055b'
|
||||
export const Y_AXIS_UUID = '680fd157-266f-4b8a-984f-cdf46b8bdf01'
|
||||
@ -168,11 +169,16 @@ export function getEventForSegmentSelection(
|
||||
// So we want to make sure we have and updated ast with
|
||||
// accurate source ranges
|
||||
const updatedAst = parse(codeManager.code)
|
||||
const node = getNodeFromPath<CallExpression>(
|
||||
if (err(updatedAst)) return null
|
||||
|
||||
const nodeMeta = getNodeFromPath<CallExpression>(
|
||||
updatedAst,
|
||||
pathToNode,
|
||||
'CallExpression'
|
||||
).node
|
||||
)
|
||||
if (err(nodeMeta)) return null
|
||||
|
||||
const node = nodeMeta.node
|
||||
const range: SourceRange = [node.start, node.end]
|
||||
return {
|
||||
type: 'Set selection',
|
||||
@ -278,14 +284,10 @@ export function processCodeMirrorRanges({
|
||||
}
|
||||
}
|
||||
|
||||
export function updateSceneObjectColors(codeBasedSelections: Selection[]) {
|
||||
let updated: Program
|
||||
try {
|
||||
updated = parse(recast(kclManager.ast))
|
||||
} catch (e) {
|
||||
console.error('error parsing code in processCodeMirrorRanges', e)
|
||||
return
|
||||
}
|
||||
function updateSceneObjectColors(codeBasedSelections: Selection[]) {
|
||||
const updated = parse(recast(kclManager.ast))
|
||||
if (err(updated)) return
|
||||
|
||||
Object.values(sceneEntitiesManager.activeSegments).forEach((segmentGroup) => {
|
||||
if (
|
||||
![STRAIGHT_SEGMENT, TANGENTIAL_ARC_TO_SEGMENT, PROFILE_START].includes(
|
||||
@ -293,11 +295,13 @@ export function updateSceneObjectColors(codeBasedSelections: Selection[]) {
|
||||
)
|
||||
)
|
||||
return
|
||||
const node = getNodeFromPath<CallExpression>(
|
||||
const nodeMeta = getNodeFromPath<CallExpression>(
|
||||
updated,
|
||||
segmentGroup.userData.pathToNode,
|
||||
'CallExpression'
|
||||
).node
|
||||
)
|
||||
if (err(nodeMeta)) return
|
||||
const node = nodeMeta.node
|
||||
const groupHasCursor = codeBasedSelections.some((selection) => {
|
||||
return isOverlap(selection.range, [node.start, node.end])
|
||||
})
|
||||
@ -571,18 +575,27 @@ export async function sendSelectEventToEngine(
|
||||
export function updateSelections(
|
||||
pathToNodeMap: PathToNodeMap,
|
||||
prevSelectionRanges: Selections,
|
||||
ast: Program
|
||||
): Selections {
|
||||
return {
|
||||
...prevSelectionRanges,
|
||||
codeBasedSelections: Object.entries(pathToNodeMap).map(
|
||||
([index, pathToNode]): Selection => {
|
||||
const node = getNodeFromPath<Value>(ast, pathToNode).node
|
||||
return {
|
||||
range: [node.start, node.end],
|
||||
type: prevSelectionRanges.codeBasedSelections[Number(index)]?.type,
|
||||
}
|
||||
ast: Program | Error
|
||||
): Selections | Error {
|
||||
if (err(ast)) return ast
|
||||
|
||||
const newSelections = Object.entries(pathToNodeMap)
|
||||
.map(([index, pathToNode]): Selection | undefined => {
|
||||
const nodeMeta = getNodeFromPath<Value>(ast, pathToNode)
|
||||
if (err(nodeMeta)) return undefined
|
||||
const node = nodeMeta.node
|
||||
return {
|
||||
range: [node.start, node.end],
|
||||
type: prevSelectionRanges.codeBasedSelections[Number(index)]?.type,
|
||||
}
|
||||
),
|
||||
})
|
||||
.filter((x?: Selection) => x !== undefined) as Selection[]
|
||||
|
||||
return {
|
||||
codeBasedSelections:
|
||||
newSelections.length > 0
|
||||
? newSelections
|
||||
: prevSelectionRanges.codeBasedSelections,
|
||||
otherSelections: prevSelectionRanges.otherSelections,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user