-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathchips.ts
More file actions
48 lines (42 loc) · 1.11 KB
/
Copy pathchips.ts
File metadata and controls
48 lines (42 loc) · 1.11 KB
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
40
41
42
43
44
45
46
47
48
export interface FileChip {
id: string;
path: string;
relPath: string;
selectionStart?: number;
selectionEnd?: number;
hidden: boolean;
}
export function makeImplicitChip(absPath: string, relPath: string): FileChip {
return {
id: `implicit:${absPath}`,
path: absPath,
relPath,
hidden: false,
};
}
let explicitChipCounter = 0;
export function makeExplicitChip(
absPath: string,
relPath: string,
selectionStart?: number,
selectionEnd?: number,
): FileChip {
explicitChipCounter += 1;
return {
id: `explicit:${absPath}:${selectionStart ?? 0}-${selectionEnd ?? 0}:${explicitChipCounter}`,
path: absPath,
relPath,
selectionStart,
selectionEnd,
hidden: false,
};
}
export function removeChip(chips: FileChip[], id: string): FileChip[] {
return chips.filter((c) => c.id !== id);
}
export function toggleChip(chips: FileChip[], id: string): FileChip[] {
return chips.map((c) => (c.id === id ? { ...c, hidden: !c.hidden } : c));
}
export function clearImplicitChips(chips: FileChip[]): FileChip[] {
return chips.filter((c) => !c.id.startsWith("implicit:"));
}