@@ -186,13 +186,9 @@ return $.widget( "ui.menu", {
186
186
} ,
187
187
188
188
_keydown : function ( event ) {
189
- var match , prev , character , skip , regex ,
189
+ var match , prev , character , skip ,
190
190
preventDefault = true ;
191
191
192
- function escape ( value ) {
193
- return value . replace ( / [ \- \[ \] { } ( ) * + ? . , \\ \^ $ | # \s ] / g, "\\$&" ) ;
194
- }
195
-
196
192
switch ( event . keyCode ) {
197
193
case $ . ui . keyCode . PAGE_UP :
198
194
this . previousPage ( event ) ;
@@ -241,10 +237,7 @@ return $.widget( "ui.menu", {
241
237
character = prev + character ;
242
238
}
243
239
244
- regex = new RegExp ( "^" + escape ( character ) , "i" ) ;
245
- match = this . activeMenu . find ( this . options . items ) . filter ( function ( ) {
246
- return regex . test ( $ ( this ) . text ( ) ) ;
247
- } ) ;
240
+ match = this . _filterMenuItems ( character ) ;
248
241
match = skip && match . index ( this . active . next ( ) ) !== - 1 ?
249
242
this . active . nextAll ( ".ui-menu-item" ) :
250
243
match ;
@@ -253,10 +246,7 @@ return $.widget( "ui.menu", {
253
246
// to move down the menu to the first item that starts with that character
254
247
if ( ! match . length ) {
255
248
character = String . fromCharCode ( event . keyCode ) ;
256
- regex = new RegExp ( "^" + escape ( character ) , "i" ) ;
257
- match = this . activeMenu . find ( this . options . items ) . filter ( function ( ) {
258
- return regex . test ( $ ( this ) . text ( ) ) ;
259
- } ) ;
249
+ match = this . _filterMenuItems ( character ) ;
260
250
}
261
251
262
252
if ( match . length ) {
@@ -640,6 +630,20 @@ return $.widget( "ui.menu", {
640
630
this . collapseAll ( event , true ) ;
641
631
}
642
632
this . _trigger ( "select" , event , ui ) ;
633
+ } ,
634
+
635
+ _filterMenuItems : function ( character ) {
636
+ var escapedCharacter = character . replace ( / [ \- \[ \] { } ( ) * + ? . , \\ \^ $ | # \s ] / g, "\\$&" ) ,
637
+ regex = new RegExp ( "^" + escapedCharacter , "i" ) ;
638
+
639
+ return this . activeMenu
640
+ . find ( this . options . items )
641
+
642
+ // Only match on items, not dividers or other content (#10571)
643
+ . filter ( ".ui-menu-item" )
644
+ . filter ( function ( ) {
645
+ return regex . test ( $ ( this ) . text ( ) ) ;
646
+ } ) ;
643
647
}
644
648
} ) ;
645
649
0 commit comments