@@ -146,14 +146,72 @@ class IssueSidebarComboList {
146
146
147
147
this . elDropdown . addEventListener ( 'click' , ( e ) => this . onItemClick ( e ) ) ;
148
148
149
+ const itemsMenu = this . elDropdown . querySelector ( '.scrolling.menu' ) || this . elDropdown . querySelector ( '.menu' ) ;
149
150
fomanticQuery ( this . elDropdown ) . dropdown ( 'setting' , {
150
151
action : 'nothing' , // do not hide the menu if user presses Enter
151
152
fullTextSearch : 'exact' ,
153
+ onShow : ( ) => hideScopedEmptyDividers ( itemsMenu ) ,
154
+ onAfterFilterItems : ( ) => hideScopedEmptyDividers ( itemsMenu ) ,
152
155
onHide : ( ) => this . onHide ( ) ,
153
156
} ) ;
154
157
}
155
158
}
156
159
160
+ export function hideScopedEmptyDividers ( container : Element ) {
161
+ const visibleItems : Element [ ] = [ ] ;
162
+ const curScopeVisibleItems : Element [ ] = [ ] ;
163
+ let curScope = '' , lastVisibleScope = '' ;
164
+ const isScopedDivider = ( item : Element ) => item . matches ( '.divider' ) && item . hasAttribute ( 'data-scope' ) ;
165
+ const hideDivider = ( item : Element ) => item . classList . add ( 'hidden' , 'transition' ) ; // dropdown has its own classes to hide items
166
+
167
+ const handleScopeSwitch = ( itemScope : string ) => {
168
+ if ( curScopeVisibleItems . length === 1 && isScopedDivider ( curScopeVisibleItems [ 0 ] ) ) {
169
+ hideDivider ( curScopeVisibleItems [ 0 ] ) ;
170
+ } else if ( curScopeVisibleItems . length ) {
171
+ if ( isScopedDivider ( curScopeVisibleItems [ 0 ] ) && lastVisibleScope === curScope ) {
172
+ hideDivider ( curScopeVisibleItems [ 0 ] ) ;
173
+ curScopeVisibleItems . shift ( ) ;
174
+ }
175
+ visibleItems . push ( ...curScopeVisibleItems ) ;
176
+ lastVisibleScope = curScope ;
177
+ }
178
+ curScope = itemScope ;
179
+ curScopeVisibleItems . length = 0 ;
180
+ } ;
181
+
182
+ // remove the scope dividers if the scope items are empty
183
+ for ( const item of container . children ) {
184
+ const itemScope = item . getAttribute ( 'data-scope' ) || '' ;
185
+ if ( itemScope !== curScope ) {
186
+ handleScopeSwitch ( itemScope ) ;
187
+ }
188
+ if ( ! item . classList . contains ( 'filtered' ) && ! item . classList . contains ( 'tw-hidden' ) ) {
189
+ curScopeVisibleItems . push ( item as HTMLElement ) ;
190
+ }
191
+ }
192
+ handleScopeSwitch ( '' ) ;
193
+
194
+ // hide all leading and trailing dividers
195
+ while ( visibleItems . length ) {
196
+ if ( ! visibleItems [ 0 ] . matches ( '.divider' ) ) break ;
197
+ hideDivider ( visibleItems [ 0 ] ) ;
198
+ visibleItems . shift ( ) ;
199
+ }
200
+ while ( visibleItems . length ) {
201
+ if ( ! visibleItems [ visibleItems . length - 1 ] . matches ( '.divider' ) ) break ;
202
+ hideDivider ( visibleItems [ visibleItems . length - 1 ] ) ;
203
+ visibleItems . pop ( ) ;
204
+ }
205
+ // hide all duplicate dividers
206
+ for ( let i = 0 ; i < visibleItems . length ; i ++ ) {
207
+ const item = visibleItems [ i ] ;
208
+ if ( ! item . matches ( '.divider' ) ) continue ;
209
+ if ( i === 0 || i === visibleItems . length - 1 || item . nextElementSibling ?. matches ( '.divider' ) ) {
210
+ hideDivider ( item ) ;
211
+ }
212
+ }
213
+ }
214
+
157
215
export function initIssueSidebarComboList ( container : HTMLElement ) {
158
216
new IssueSidebarComboList ( container ) . init ( ) ;
159
217
}
0 commit comments