Skip to content

Commit

Permalink
fix count in getSelectionType
Browse files Browse the repository at this point in the history
used to count only same type as first selection
  • Loading branch information
max-mrgrsk committed Sep 14, 2024
1 parent 40c77d4 commit 434a8de
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/lib/selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,25 +459,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
}
})
.reduce((acc, [type, count]) => {
const foundIndex = acc.findIndex((item) => item && item[0] === type)

if (foundIndex === -1) {
return [...acc, [type, count]]
} else {
const temp = [...acc]
temp[foundIndex][1] += count
return temp
}
}, [] as ResolvedSelectionType[])
const extrudableCount = selection.codeBasedSelections.filter((_, i) => {
const singleSelection = {
...selection,
codeBasedSelections: [selection.codeBasedSelections[i]],
}
return canExtrudeSelectionItem(singleSelection, 0)
}).length

return extrudableCount === selection.codeBasedSelections.length
? [['extrude-wall', extrudableCount]]
: [['other', selection.codeBasedSelections.length]]
}

export function getSelectionTypeDisplayText(
Expand Down

0 comments on commit 434a8de

Please sign in to comment.