@@ -11,7 +11,7 @@ import type {AnimatedTextInputRef} from '@components/RNTextInput';
1111import type { GetAdditionalSectionsCallback } from '@components/Search/SearchAutocompleteList' ;
1212import SearchAutocompleteList from '@components/Search/SearchAutocompleteList' ;
1313import SearchInputSelectionWrapper from '@components/Search/SearchInputSelectionWrapper' ;
14- import type { SearchQueryString } from '@components/Search/types' ;
14+ import type { SearchFilterKey , SearchQueryString } from '@components/Search/types' ;
1515import type { SearchQueryItem } from '@components/SelectionList/Search/SearchQueryListItem' ;
1616import { isSearchQueryItem } from '@components/SelectionList/Search/SearchQueryListItem' ;
1717import type { SelectionListHandle } from '@components/SelectionList/types' ;
@@ -350,10 +350,30 @@ function SearchRouter({onRouterClose, shouldHideInputCaret, isSearchRouterDispla
350350 } ) ;
351351 } else if ( item . searchItemType === CONST . SEARCH . SEARCH_ROUTER_ITEM_TYPE . AUTOCOMPLETE_SUGGESTION && textInputValue ) {
352352 const fieldKey = item . mapKey ?. includes ( ':' ) ? item . mapKey . split ( ':' ) . at ( 0 ) : item . mapKey ;
353- const keyIndex = fieldKey ? textInputValue . toLowerCase ( ) . lastIndexOf ( `${ fieldKey } :` ) : - 1 ;
354-
355- const trimmedUserSearchQuery =
356- keyIndex !== - 1 && fieldKey ? textInputValue . substring ( 0 , keyIndex + fieldKey . length + 1 ) : getQueryWithoutAutocompletedPart ( textInputValue ) ;
353+ const nameFields = [
354+ CONST . SEARCH . SYNTAX_FILTER_KEYS . TO ,
355+ CONST . SEARCH . SYNTAX_FILTER_KEYS . FROM ,
356+ CONST . SEARCH . SYNTAX_FILTER_KEYS . ASSIGNEE ,
357+ CONST . SEARCH . SYNTAX_FILTER_KEYS . PAYER ,
358+ CONST . SEARCH . SYNTAX_FILTER_KEYS . EXPORTER ,
359+ ] as SearchFilterKey [ ] ;
360+ const isNameField = fieldKey && nameFields . includes ( fieldKey as SearchFilterKey ) ;
361+
362+ let trimmedUserSearchQuery ;
363+ if ( isNameField && fieldKey ) {
364+ const fieldPattern = `${ fieldKey } :` ;
365+ const keyIndex = textInputValue . toLowerCase ( ) . lastIndexOf ( fieldPattern . toLowerCase ( ) ) ;
366+
367+ if ( keyIndex !== - 1 ) {
368+ trimmedUserSearchQuery = textInputValue . substring ( 0 , keyIndex + fieldPattern . length ) ;
369+ } else {
370+ trimmedUserSearchQuery = getQueryWithoutAutocompletedPart ( textInputValue ) ;
371+ }
372+ } else {
373+ const keyIndex = fieldKey ? textInputValue . toLowerCase ( ) . lastIndexOf ( `${ fieldKey } :` ) : - 1 ;
374+ trimmedUserSearchQuery =
375+ keyIndex !== - 1 && fieldKey ? textInputValue . substring ( 0 , keyIndex + fieldKey . length + 1 ) : getQueryWithoutAutocompletedPart ( textInputValue ) ;
376+ }
357377
358378 const newSearchQuery = `${ trimmedUserSearchQuery } ${ sanitizeSearchValue ( item . searchQuery ) } \u00A0` ;
359379 onSearchQueryChange ( newSearchQuery , true ) ;
0 commit comments