1+ /*
2+ * Autocomplete History - Copyright (c) 2026 InnoGames GmbH
3+ *
4+ * This module ads auto complete while searching the query history
5+ */
6+
7+ servershell . autocomplete_history_enabled = false ;
8+
9+ servershell . close_history_autocomplete = function ( ) {
10+ const autocomplete_search_input = $ ( '#term' ) ;
11+ autocomplete_search_input . autocomplete ( 'destroy' ) ;
12+ servershell . autocomplete_history_enabled = false ;
13+ servershell . enable_search_autocomplete ( ) ;
14+ $ ( '#history-toggle' ) . removeClass ( 'active' ) ;
15+ }
16+
17+ servershell . open_history_autocomplete = function ( ) {
18+ const autocomplete_search_input = $ ( '#term' ) ;
19+ autocomplete_search_input . autocomplete ( 'destroy' ) ;
20+ autocomplete_search_input . autocomplete ( {
21+ source : function ( request , response ) {
22+ const displayLimit = 20 ;
23+ const search = request . term ;
24+
25+ const history = servershell . history . get ( )
26+ const possibleChoices = history . filter ( ( entry ) => entry . term . toLowerCase ( ) . includes ( search . toLowerCase ( ) ) )
27+ . map ( ( entry ) => entry . term ) ;
28+ response ( possibleChoices . slice ( 0 , Math . min ( displayLimit , possibleChoices . length ) ) ) ;
29+ } ,
30+
31+ select : function ( _ , ui ) {
32+ const term = ui . item . value ;
33+ const [ , entry ] = servershell . history . findMatchingEntry ( term ) ;
34+
35+ servershell . term = term ;
36+
37+ const manageAttributes = $ ( '#history_attributes' ) [ 0 ] . checked ;
38+ if ( manageAttributes && entry ) {
39+ servershell . shown_attributes = entry . shown_attributes ;
40+ } else {
41+ servershell . submit_search ( ) ;
42+ }
43+ servershell . close_history_autocomplete ( ) ;
44+ }
45+ } ) ;
46+ autocomplete_search_input . autocomplete ( 'enable' ) ;
47+ autocomplete_search_input . autocomplete ( 'option' , 'autoFocus' , $ ( '#autoselect' ) [ 0 ] . checked ) ;
48+ autocomplete_search_input . autocomplete ( 'option' , 'minLength' , 0 ) ;
49+ autocomplete_search_input . autocomplete ( 'option' , 'delay' , $ ( '#autocomplete_delay_search' ) [ 0 ] . value ) ;
50+
51+ // When history is opened show all item, regardless of the current input text
52+ autocomplete_search_input . autocomplete ( 'search' , "" ) ;
53+ autocomplete_search_input . focus ( ) ;
54+ servershell . autocomplete_history_enabled = true ;
55+ $ ( '#history-toggle' ) . addClass ( 'active' ) ;
56+ }
57+
58+ $ ( document ) . ready ( function ( ) {
59+ $ ( document ) . keydown ( function ( event ) {
60+ if ( event . shiftKey && event . ctrlKey ) {
61+ if ( event . key !== 'F' ) {
62+ return ;
63+ }
64+ if ( servershell . autocomplete_history_enabled ) {
65+ servershell . close_history_autocomplete ( ) ;
66+ return ;
67+ }
68+ servershell . open_history_autocomplete ( ) ;
69+ }
70+ } ) ;
71+ } ) ;
0 commit comments