File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -541,7 +541,7 @@ <h1>Clippy Lints</h1>
541
541
< div class ="col-12 col-md-5 search-control ">
542
542
< div class ="input-group ">
543
543
< label class ="input-group-addon " id ="filter-label " for ="search-input "> Filter:</ label >
544
- < input type ="text " class ="form-control filter-input " placeholder ="Keywords or search string " id ="search-input "
544
+ < input type ="text " class ="form-control filter-input " placeholder ="Keywords or search string (`S` or `/` to focus) " id ="search-input "
545
545
ng-model ="search " ng-blur ="updatePath() " ng-keyup ="$event.keyCode == 13 && updatePath() "
546
546
ng-model-options ="{debounce: 50} " />
547
547
< span class ="input-group-btn ">
Original file line number Diff line number Diff line change @@ -579,6 +579,40 @@ function setTheme(theme, store) {
579
579
}
580
580
}
581
581
582
+ function getVirtualKey ( ev ) {
583
+ if ( "key" in ev && typeof ev . key !== "undefined" ) {
584
+ return ev . key ;
585
+ }
586
+
587
+ const c = ev . charCode || ev . keyCode ;
588
+ if ( c === 27 ) {
589
+ return "Escape" ;
590
+ }
591
+ return String . fromCharCode ( c ) ;
592
+ }
593
+
594
+ function handleShortcut ( ev ) {
595
+ if ( document . activeElement . tagName === "INPUT" ) {
596
+ if ( getVirtualKey ( ev ) === "Escape" ) {
597
+ document . activeElement . blur ( ) ;
598
+ }
599
+ } else {
600
+ switch ( getVirtualKey ( ev ) ) {
601
+ case "s" :
602
+ case "S" :
603
+ case "/" :
604
+ ev . preventDefault ( ) ; // To prevent the kep to be put into the input.
605
+ document . getElementById ( "search-input" ) . focus ( ) ;
606
+ break ;
607
+ default :
608
+ break ;
609
+ }
610
+ }
611
+ }
612
+
613
+ document . addEventListener ( "keypress" , handleShortcut ) ;
614
+ document . addEventListener ( "keydown" , handleShortcut ) ;
615
+
582
616
// loading the theme after the initial load
583
617
const prefersDark = window . matchMedia ( "(prefers-color-scheme: dark)" ) ;
584
618
const theme = localStorage . getItem ( 'clippy-lint-list-theme' ) ;
You can’t perform that action at this time.
0 commit comments