in packages/attribute-slicer/src/selection/SelectionManager.ts [203:243]
public itemClicked(item: T): void {
// Toggles the selected item out of the selection
const toggleItem: Function = (): void => {
const idx: number = this.findIndex(item);
const newSel: T[] = this.selection.slice(0);
if (idx < 0) {
newSel.push(item);
} else {
newSel.splice(idx, 1);
}
this.selection = newSel;
};
if (!this.keyState.ctrl) {
// If the user just selected the first item
if (this.keyState.shift && !this.shiftPivot) {
this.shiftPivot = item;
}
if (this.keyState.shift && this.items && this.items.length) {
const idx: number = this.findIndex(this.shiftPivot, this.items);
const lastIdx: number = this.findIndex(item, this.items);
// The selection is the range between the first and second indexes
this.selection = this.items.slice(
idx < lastIdx ? idx : lastIdx,
(idx < lastIdx ? lastIdx : idx) + 1,
);
} else if (this.internalBrushMode) {
// If the user is in "brush" mode, but just single clicks an item,
// then just deselect it, otherwise set the item
this.selection =
this.selection.length === 1 && this.selection[0].id === item.id
? []
: [item];
} else {
toggleItem();
}
} else {
toggleItem();
}
}