@@ -86,14 +86,17 @@ export function filterItems (
86
86
noFilter ?: boolean
87
87
} ,
88
88
) {
89
- const array : { index : number , matches : Record < string , FilterMatchArrayMultiple | undefined > } [ ] = [ ]
89
+ type FilterResult = { index : number , matches : Record < string , FilterMatchArrayMultiple | undefined > , type ?: 'divider' | 'subheader' }
90
+ const array : FilterResult [ ] = [ ]
90
91
// always ensure we fall back to a functioning filter
91
92
const filter = options ?. default ?? defaultFilter
92
93
const keys = options ?. filterKeys ? wrapInArray ( options . filterKeys ) : false
93
94
const customFiltersLength = Object . keys ( options ?. customKeyFilter ?? { } ) . length
94
95
95
96
if ( ! items ?. length ) return array
96
97
98
+ let lookAheadItem : FilterResult | null = null
99
+
97
100
loop:
98
101
for ( let i = 0 ; i < items . length ; i ++ ) {
99
102
const [ item , transformed = item ] = wrapInArray ( items [ i ] ) as readonly [ InternalItem , { } ]
@@ -104,6 +107,11 @@ export function filterItems (
104
107
if ( ( query || customFiltersLength > 0 ) && ! options ?. noFilter ) {
105
108
if ( typeof item === 'object' ) {
106
109
if ( item . type === 'divider' || item . type === 'subheader' ) {
110
+ if ( lookAheadItem ?. type === 'divider' && item . type === 'subheader' ) {
111
+ array . push ( lookAheadItem ) // divider before subheader
112
+ }
113
+
114
+ lookAheadItem = { index : i , matches : { } , type : item . type }
107
115
continue
108
116
}
109
117
@@ -151,6 +159,11 @@ export function filterItems (
151
159
) continue
152
160
}
153
161
162
+ if ( lookAheadItem ) {
163
+ array . push ( lookAheadItem )
164
+ lookAheadItem = null
165
+ }
166
+
154
167
array . push ( { index : i , matches : { ...defaultMatches , ...customMatches } } )
155
168
}
156
169
0 commit comments