Users should be able to select points (not just lines) (#97)

* update selection datastructure to accomodate more selection metadata

* Users should be able to select points (not just lines)
This commit is contained in:
Kurt Hutten
2023-04-03 16:05:25 +10:00
committed by GitHub
parent 7013eb861d
commit a8b68bab6a
25 changed files with 292 additions and 146 deletions

View File

@ -9,6 +9,7 @@ import {
import { recast } from '../recast'
import { initPromise } from '../rust'
import { getSketchSegmentFromSourceRange } from './sketchConstraints'
import { Selection } from '../../useStore'
beforeAll(() => initPromise)
@ -26,23 +27,30 @@ function testingSwapSketchFnCall({
originalRange: [number, number]
} {
const startIndex = inputCode.indexOf(callToSwap)
const range: [number, number] = [startIndex, startIndex + callToSwap.length]
const range: Selection = {
type: 'default',
range: [startIndex, startIndex + callToSwap.length],
}
const tokens = lexer(inputCode)
const ast = abstractSyntaxTree(tokens)
const programMemory = executor(ast)
const transformInfos = getTransformInfos([range], ast, constraintType)
const selections = {
codeBasedSelections: [range],
otherSelections: [],
}
const transformInfos = getTransformInfos(selections, ast, constraintType)
if (!transformInfos) throw new Error('nope')
const { modifiedAst } = transformAstSketchLines({
ast,
programMemory,
selectionRanges: [range],
selectionRanges: selections,
transformInfos,
referenceSegName: '',
})
return {
newCode: recast(modifiedAst),
originalRange: range,
originalRange: range.range,
}
}