@@ -17,7 +17,12 @@ class CommandSearchSource extends BaseSearchSource<CommandSuggestion> {
17
17
this . channel = channel ;
18
18
}
19
19
20
- protected query ( searchQuery : string ) {
20
+ canExecuteQuery = ( newSearchString ?: string ) => {
21
+ const hasNewSearchQuery = typeof newSearchString !== 'undefined' ;
22
+ return this . isActive && ! this . isLoading && ( this . hasNext || hasNewSearchQuery ) ;
23
+ } ;
24
+
25
+ query ( searchQuery : string ) {
21
26
const channelConfig = this . channel . getConfig ( ) ;
22
27
const commands = channelConfig ?. commands || [ ] ;
23
28
const selectedCommands : ( CommandResponse & { name : string } ) [ ] = commands . filter (
@@ -80,6 +85,9 @@ export const createCommandsMiddleware = (
80
85
options ?: TextComposerMiddlewareOptions ,
81
86
) => {
82
87
const finalOptions = mergeWith ( DEFAULT_OPTIONS , options ?? { } ) ;
88
+ const searchSource = new CommandSearchSource ( channel ) ;
89
+ searchSource . activate ( ) ;
90
+
83
91
return {
84
92
id : finalOptions . trigger ,
85
93
onChange : ( { input, nextHandler } : MiddlewareParams < CommandSuggestion > ) => {
@@ -92,13 +100,15 @@ export const createCommandsMiddleware = (
92
100
) ;
93
101
94
102
if ( ! lastToken || lastToken . length < finalOptions . minChars ) {
95
- // check whether suggestions already exist and if so remove them
96
- return nextHandler ( input ) ;
103
+ const hasStaleSuggestions =
104
+ input . state . suggestions ?. trigger === finalOptions . trigger ;
105
+ const newInput = { ...input } ;
106
+ if ( hasStaleSuggestions ) {
107
+ delete newInput . state . suggestions ;
108
+ }
109
+ return nextHandler ( newInput ) ;
97
110
}
98
111
99
- const searchSource = new CommandSearchSource ( channel ) ;
100
- searchSource . activate ( ) ;
101
-
102
112
return Promise . resolve ( {
103
113
state : {
104
114
...state ,
0 commit comments