@aliou/pi-utils-settings 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -328,6 +328,9 @@ export class SectionedSettings implements Component {
|
|
|
328
328
|
/**
|
|
329
329
|
* Apply search filter to entries without resetting the cursor.
|
|
330
330
|
* Used by updateSections() to preserve selection.
|
|
331
|
+
*
|
|
332
|
+
* Matches on both item labels and section labels. When a section label
|
|
333
|
+
* matches, all items in that section are included.
|
|
331
334
|
*/
|
|
332
335
|
private filterEntries(query: string): void {
|
|
333
336
|
if (!query) {
|
|
@@ -335,29 +338,49 @@ export class SectionedSettings implements Component {
|
|
|
335
338
|
return;
|
|
336
339
|
}
|
|
337
340
|
|
|
341
|
+
const q = query.toLowerCase();
|
|
338
342
|
const filtered: FlatEntry[] = [];
|
|
339
343
|
let currentSection: FlatEntry | null = null;
|
|
344
|
+
let sectionLabelMatches = false;
|
|
340
345
|
let sectionHasMatch = false;
|
|
346
|
+
let sectionItems: FlatEntry[] = [];
|
|
347
|
+
|
|
348
|
+
const flushSection = () => {
|
|
349
|
+
if (sectionLabelMatches && currentSection) {
|
|
350
|
+
// Section label matched: include header + all items
|
|
351
|
+
filtered.push(currentSection);
|
|
352
|
+
filtered.push(...sectionItems);
|
|
353
|
+
} else if (sectionHasMatch && currentSection) {
|
|
354
|
+
// Only some items matched: include header + matched items
|
|
355
|
+
filtered.push(currentSection);
|
|
356
|
+
for (const item of sectionItems) {
|
|
357
|
+
if (item.item && item.item.label.toLowerCase().includes(q)) {
|
|
358
|
+
filtered.push(item);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
};
|
|
341
363
|
|
|
342
364
|
for (const entry of this.flatEntries) {
|
|
343
365
|
if (entry.type === "section") {
|
|
366
|
+
flushSection();
|
|
344
367
|
currentSection = entry;
|
|
345
|
-
|
|
368
|
+
sectionLabelMatches = (entry.sectionLabel ?? "")
|
|
369
|
+
.toLowerCase()
|
|
370
|
+
.includes(q);
|
|
371
|
+
sectionHasMatch = sectionLabelMatches;
|
|
372
|
+
sectionItems = [];
|
|
346
373
|
continue;
|
|
347
374
|
}
|
|
348
375
|
|
|
349
376
|
if (entry.item) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (currentSection && !sectionHasMatch) {
|
|
354
|
-
filtered.push(currentSection);
|
|
355
|
-
sectionHasMatch = true;
|
|
356
|
-
}
|
|
357
|
-
filtered.push(entry);
|
|
377
|
+
sectionItems.push(entry);
|
|
378
|
+
if (entry.item.label.toLowerCase().includes(q)) {
|
|
379
|
+
sectionHasMatch = true;
|
|
358
380
|
}
|
|
359
381
|
}
|
|
360
382
|
}
|
|
383
|
+
flushSection();
|
|
361
384
|
|
|
362
385
|
this.filteredEntries = filtered;
|
|
363
386
|
}
|
package/package.json
CHANGED