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