-
Notifications
You must be signed in to change notification settings - Fork 208
/
SelectionHelper.ts
39 lines (36 loc) · 1.22 KB
/
SelectionHelper.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module UnifiedSelection
*/
import { Key, Keys, NodeKey } from "@itwin/presentation-common";
/**
* Helper class for working with selection.
* @public
*/
export class SelectionHelper {
// istanbul ignore next
private constructor() {}
/**
* Re-map the given keyset for selection. This means all instance node keys get converted
* to instance keys, because in that case we want to select instances instead of nodes. All
* other types of keys ar left as is.
*/
public static getKeysForSelection(keys: Readonly<Keys>): Key[] {
const result = new Array<Key>();
keys.forEach((key: Key) => {
if (Key.isNodeKey(key)) {
if (NodeKey.isInstancesNodeKey(key)) {
result.push(...key.instanceKeys);
} else {
result.push(key);
}
} else {
result.push(key);
}
});
return result;
}
}