File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 37
37
return ;
38
38
}
39
39
40
- const searchTerm = ((value as string ) || " " ).toLowerCase ();
40
+ const fullSearchTerm = ((value as string ) || ' ' ).toLowerCase ();
41
+ const lastSpaceIndex = fullSearchTerm .lastIndexOf (' ' );
42
+ const searchTerm = lastSpaceIndex === - 1 ? fullSearchTerm : fullSearchTerm .substring (lastSpaceIndex + 1 );
41
43
42
44
if (searchTerm === " " && ! backspaceUsed ) {
43
45
filteredSuggestions = [];
111
113
}
112
114
113
115
function selectItem(item : string ) {
114
- value = item ;
116
+ const currentValue = (value as string ) || ' ' ;
117
+ const lastSpaceIndex = currentValue .lastIndexOf (' ' );
118
+
119
+ if (lastSpaceIndex === - 1 ) {
120
+ value = item + ' ' ; // Replace the whole value if no space, add trailing space
121
+ } else {
122
+ value = currentValue .substring (0 , lastSpaceIndex + 1 ) + item + ' ' ; // Replace last word, add trailing space
123
+ }
124
+
115
125
if (onSelect ) onSelect (item );
116
126
filteredSuggestions = [];
117
127
selectedIndex = - 1 ;
Original file line number Diff line number Diff line change 52
52
return ;
53
53
}
54
54
55
- const searchTerm = ((value as string ) || " " ).toLowerCase ();
55
+ const fullSearchTerm = ((value as string ) || ' ' ).toLowerCase ();
56
+ const lastSpaceIndex = fullSearchTerm .lastIndexOf (' ' );
57
+ const searchTerm = lastSpaceIndex === - 1 ? fullSearchTerm : fullSearchTerm .substring (lastSpaceIndex + 1 );
56
58
57
59
// Show suggestions if:
58
60
// 1. There's actual input text, OR
169
171
}
170
172
171
173
function selectItem(item : string ) {
172
- value = item ;
174
+ const currentValue = (value as string ) || ' ' ;
175
+ const lastSpaceIndex = currentValue .lastIndexOf (' ' );
176
+
177
+ if (lastSpaceIndex === - 1 ) {
178
+ value = item + ' ' ; // Replace the whole value if no space, add trailing space
179
+ } else {
180
+ value = currentValue .substring (0 , lastSpaceIndex + 1 ) + item + ' ' ; // Replace last word, add trailing space
181
+ }
173
182
174
183
if (onSelect ) {
175
184
onSelect (item );
You can’t perform that action at this time.
0 commit comments