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:
Kurt Hutten
2023-04-14 07:49:36 +10:00
committed by GitHub
parent 2fc68e7c82
commit 15699361a0
17 changed files with 410 additions and 312 deletions

28
src/lang/util.ts Normal file
View 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)
}
}