@@ -11,7 +11,8 @@ import type { Channel } from '../../../channel';
11
11
import type { TextComposerSuggestion } from '../../types' ;
12
12
13
13
type CommandSuggestion = TextComposerSuggestion < CommandResponse > ;
14
- class CommandSearchSource extends BaseSearchSource < CommandSuggestion > {
14
+
15
+ export class CommandSearchSource extends BaseSearchSource < CommandSuggestion > {
15
16
readonly type = 'commands' ;
16
17
private channel : Channel ;
17
18
@@ -25,7 +26,7 @@ class CommandSearchSource extends BaseSearchSource<CommandSuggestion> {
25
26
return this . isActive && ! this . isLoading && ( this . hasNext || hasNewSearchQuery ) ;
26
27
} ;
27
28
28
- protected getStateBeforeFirstQuery ( newSearchString : string ) {
29
+ getStateBeforeFirstQuery ( newSearchString : string ) {
29
30
const newState = super . getStateBeforeFirstQuery ( newSearchString ) ;
30
31
const { items } = this . state . getLatestValue ( ) ;
31
32
return {
@@ -39,7 +40,10 @@ class CommandSearchSource extends BaseSearchSource<CommandSuggestion> {
39
40
const commands = channelConfig ?. commands || [ ] ;
40
41
const selectedCommands : ( CommandResponse & { name : string } ) [ ] = commands . filter (
41
42
( command ) : command is CommandResponse & { name : string } =>
42
- ! ! ( command . name && command . name . indexOf ( searchQuery ) !== - 1 ) ,
43
+ ! ! (
44
+ command . name &&
45
+ command . name . toLowerCase ( ) . indexOf ( searchQuery . toLowerCase ( ) ) !== - 1
46
+ ) ,
43
47
) ;
44
48
45
49
// sort alphabetically unless you're matching the first char
@@ -94,10 +98,16 @@ const DEFAULT_OPTIONS: TextComposerMiddlewareOptions = { minChars: 1, trigger: '
94
98
95
99
export const createCommandsMiddleware = (
96
100
channel : Channel ,
97
- options ?: TextComposerMiddlewareOptions ,
101
+ options ?: Partial < TextComposerMiddlewareOptions > & {
102
+ searchSource ?: CommandSearchSource ;
103
+ } ,
98
104
) => {
99
105
const finalOptions = mergeWith ( DEFAULT_OPTIONS , options ?? { } ) ;
100
- const searchSource = new CommandSearchSource ( channel ) ;
106
+ let searchSource = new CommandSearchSource ( channel ) ;
107
+ if ( options ?. searchSource ) {
108
+ searchSource = options . searchSource ;
109
+ searchSource . resetState ( ) ;
110
+ }
101
111
searchSource . activate ( ) ;
102
112
103
113
return {
0 commit comments