Cursors should stay after a code-mod (#113)
* setup to get path to nodes back from ast-mods * fix cursor setting for constraint buttons that use transformSecondarySketchLinesTagFirst * fix cursors for constraints that use transformAstSketchLines
This commit is contained in:
28
src/lang/util.ts
Normal file
28
src/lang/util.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { Selections, StoreState } from '../useStore'
|
||||
import { Program } from './abstractSyntaxTree'
|
||||
import { PathToNode } from './executor'
|
||||
import { getNodeFromPath } from './queryAst'
|
||||
|
||||
export function updateCursors(
|
||||
setCursor: StoreState['setCursor'],
|
||||
selectionRanges: Selections,
|
||||
pathToNodeMap: { [key: number]: PathToNode }
|
||||
): (newAst: Program) => void {
|
||||
return (newAst: Program) => {
|
||||
const newSelections: Selections = {
|
||||
...selectionRanges,
|
||||
codeBasedSelections: [],
|
||||
}
|
||||
Object.entries(pathToNodeMap).forEach(([index, path]) => {
|
||||
const node = getNodeFromPath(newAst, path).node as any
|
||||
const type = selectionRanges.codeBasedSelections[Number(index)].type
|
||||
if (node) {
|
||||
newSelections.codeBasedSelections.push({
|
||||
range: [node.start, node.end],
|
||||
type: type || 'default',
|
||||
})
|
||||
}
|
||||
})
|
||||
setCursor(newSelections)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user