Enable/disable "start sketch", "edit sketch" and "extrude" appropriately (#1449)

* test that fails for when to enable extrude and sketch features

* add fix to make test pass

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Kurt Hutten
2024-02-19 17:23:03 +11:00
committed by GitHub
parent ad7c544754
commit de5885ce0b
7 changed files with 155 additions and 15 deletions

View File

@ -1,5 +1,5 @@
import { ToolTip } from '../useStore'
import { Selection } from 'lib/selections'
import { Selection, Selections } from 'lib/selections'
import {
BinaryExpression,
Program,
@ -558,3 +558,24 @@ export function hasExtrudeSketchGroup({
const varValue = programMemory?.root[varName]
return varValue?.type === 'ExtrudeGroup' || varValue?.type === 'SketchGroup'
}
export function isSingleCursorInPipe(
selectionRanges: Selections,
ast: Program
) {
if (selectionRanges.codeBasedSelections.length !== 1) return false
if (
doesPipeHaveCallExp({
ast,
selection: selectionRanges.codeBasedSelections[0],
calleeName: 'extrude',
})
)
return false
const selection = selectionRanges.codeBasedSelections[0]
const pathToNode = getNodePathFromSourceRange(ast, selection.range)
const nodeTypes = pathToNode.map(([, type]) => type)
if (nodeTypes.includes('FunctionExpression')) return false
if (nodeTypes.includes('PipeExpression')) return true
return false
}