Skip to content

Commit bdd387d

Browse files
Handle grouping for folders and files with brackets
1 parent f961a13 commit bdd387d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/core/treeNodeValue.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class _TreeNodeValueBase {
9090
return this._type === TreeNodeType.static
9191
}
9292

93+
isGroup(): this is TreeNodeValueGroup {
94+
return this._type === TreeNodeType.group
95+
}
9396
get overrides() {
9497
return [...this._overrides.entries()]
9598
.sort(([nameA], [nameB]) =>
@@ -201,7 +204,27 @@ export class TreeNodeValueParam extends _TreeNodeValueBase {
201204
}
202205
}
203206

204-
export type TreeNodeValue = TreeNodeValueStatic | TreeNodeValueParam
207+
export class TreeNodeValueGroup extends _TreeNodeValueBase {
208+
override _type: TreeNodeType.group = TreeNodeType.group
209+
210+
constructor(
211+
rawSegment: string,
212+
parent: TreeNodeValue | undefined,
213+
pathSegment: string = rawSegment,
214+
subSegments: SubSegment[] = [pathSegment]
215+
) {
216+
// Sanitize both rawSegment and pathSegment
217+
const sanitizedRawSegment = rawSegment.replace(/\(.*?\)/g, '')
218+
const sanitizedPathSegment = pathSegment.replace(/\(.*?\)/g, '')
219+
220+
super(sanitizedRawSegment, parent, sanitizedPathSegment, subSegments)
221+
}
222+
}
223+
224+
export type TreeNodeValue =
225+
| TreeNodeValueStatic
226+
| TreeNodeValueParam
227+
| TreeNodeValueGroup
205228

206229
export interface TreeNodeValueOptions extends ParseSegmentOptions {
207230
/**
@@ -226,6 +249,10 @@ export function createTreeNodeValue(
226249
parent?: TreeNodeValue,
227250
options: TreeNodeValueOptions = {}
228251
): TreeNodeValue {
252+
// Check if the segment represents a group file (contains `()`)
253+
if (segment.includes('(') && segment.includes(')')) {
254+
return new TreeNodeValueGroup(segment, parent)
255+
}
229256
if (!segment || segment === 'index') {
230257
return new TreeNodeValueStatic(segment, parent, '')
231258
}

0 commit comments

Comments
 (0)