| 143 | } |
| 144 | |
| 145 | function buildGroupDecos(state) { |
| 146 | const doc = state.doc; |
| 147 | const folded = state.field(foldState, false) || new Set(); |
| 148 | // No removed groups |
| 149 | const fns = |
| 150 | (typeof getFileNames === "function" ? getFileNames() : []) || []; |
| 151 | if (isGhostText || !fns.length || doc.length === 0 || doc.lines === 0) |
| 152 | return Decoration.none; |
| 153 | |
| 154 | const builder = []; |
| 155 | // Build header chevrons and collapses per group |
| 156 | let groupIndex = 0; |
| 157 | eachGroup(doc, ({ start, end }) => { |
| 158 | const header = doc.line(start); |
| 159 | const key = start - 1; |
| 160 | const collapsed = folded.has(key); // zero-based line index |
| 161 | // Header line class and chevron widget |
| 162 | builder.push( |
| 163 | Decoration.line({ class: "cm-fileName" }).range(header.from), |
| 164 | ); |
| 165 | // File icon |
| 166 | const fileNames = |
| 167 | (typeof getFileNames === "function" ? getFileNames() : []) || []; |
| 168 | const fileInfo = fileNames[groupIndex] || {}; |
| 169 | const fname = |
| 170 | typeof fileInfo === "string" ? fileInfo : fileInfo.name || ""; |
| 171 | const iconClass = helpers.getIconForFile(fname); |
| 172 | builder.push( |
| 173 | Decoration.widget({ |
| 174 | widget: new FileIconWidget(iconClass), |
| 175 | side: -1, |
| 176 | }).range(header.from), |
| 177 | ); |
| 178 | // Count badge on right |
| 179 | const count = |
| 180 | typeof fileInfo === "object" && Number.isFinite(fileInfo.count) |
| 181 | ? fileInfo.count |
| 182 | : Math.max(0, end - start); |
| 183 | builder.push( |
| 184 | Decoration.widget({ widget: new CountWidget(count), side: 1 }).range( |
| 185 | header.to, |
| 186 | ), |
| 187 | ); |
| 188 | builder.push( |
| 189 | Decoration.widget({ |
| 190 | widget: new ChevronWidget(collapsed), |
| 191 | side: 1, |
| 192 | }).range(header.to), |
| 193 | ); |
| 194 | |
| 195 | if (collapsed && end > start) { |
| 196 | // Hide content lines and show a summary placeholder |
| 197 | const first = doc.line(start + 1); |
| 198 | const last = doc.line(end); |
| 199 | builder.push( |
| 200 | Decoration.replace({ block: true }).range(first.from, last.to), |
| 201 | ); |
| 202 | const count2 = count; |