Fix canExtrudeSelectionItem and getSelectionType for multiple selections (#3884)

* fix isSketchPipe in canExtrudeSelectionItem

* fix count in getSelectionType

used to count only same type as first selection
This commit is contained in:
max
2024-09-17 22:32:07 +02:00
committed by GitHub
parent f828c36e58
commit 62b78840b6

View File

@ -438,10 +438,14 @@ export function canFilletSelection(selection: Selections) {
}
function canExtrudeSelectionItem(selection: Selections, i: number) {
const isolatedSelection = {
...selection,
codeBasedSelections: [selection.codeBasedSelections[i]],
}
const commonNode = buildCommonNodeFromSelection(selection, i)
return (
!!isSketchPipe(selection) &&
!!isSketchPipe(isolatedSelection) &&
nodeHasClose(commonNode) &&
!nodeHasExtrude(commonNode)
)
@ -460,25 +464,17 @@ export type ResolvedSelectionType = [Selection['type'] | 'other', number]
export function getSelectionType(
selection: Selections
): ResolvedSelectionType[] {
return selection.codeBasedSelections
.map((s, i) => {
if (canExtrudeSelectionItem(selection, i)) {
return ['extrude-wall', 1] as ResolvedSelectionType // This is implicitly determining what a face is, which is bad
} else {
return ['other', 1] as ResolvedSelectionType
const extrudableCount = selection.codeBasedSelections.filter((_, i) => {
const singleSelection = {
...selection,
codeBasedSelections: [selection.codeBasedSelections[i]],
}
})
.reduce((acc, [type, count]) => {
const foundIndex = acc.findIndex((item) => item && item[0] === type)
return canExtrudeSelectionItem(singleSelection, 0)
}).length
if (foundIndex === -1) {
return [...acc, [type, count]]
} else {
const temp = [...acc]
temp[foundIndex][1] += count
return temp
}
}, [] as ResolvedSelectionType[])
return extrudableCount === selection.codeBasedSelections.length
? [['extrude-wall', extrudableCount]]
: [['other', selection.codeBasedSelections.length]]
}
export function getSelectionTypeDisplayText(