@@ -771,8 +771,8 @@ var Geosuggest = (function (React) {
771771 /**
772772 * Makes a text bold
773773 */
774- SuggestItem . prototype . makeBold = function ( element , key ) {
775- return ( React__namespace . createElement ( "b" , { className : "geosuggest__item__matched-text" , key : key } , element ) ) ;
774+ SuggestItem . prototype . makeBold = function ( element ) {
775+ return React__namespace . createElement ( "b" , { className : "geosuggest__item__matched-text" } , element ) ;
776776 } ;
777777 /**
778778 * Replace matched text with the same in bold
@@ -781,22 +781,25 @@ var Geosuggest = (function (React) {
781781 if ( ! userInput || ! suggest . matchedSubstrings ) {
782782 return suggest . label ;
783783 }
784- var start = suggest . matchedSubstrings . offset ;
785- var length = suggest . matchedSubstrings . length ;
786- var end = start + length ;
787- var boldPart = this . makeBold ( suggest . label . substring ( start , end ) , suggest . label ) ;
788- var pre = '' ;
789- var post = '' ;
790- if ( start > 0 ) {
791- pre = suggest . label . slice ( 0 , start ) ;
784+ var parts = [ ] ;
785+ var previousEnd = 0 ;
786+ for ( var _i = 0 , _a = suggest . matchedSubstrings ; _i < _a . length ; _i ++ ) {
787+ var _b = _a [ _i ] , start = _b . offset , length_1 = _b . length ;
788+ // Add non-matching substring before and between matches
789+ if ( start > previousEnd ) {
790+ parts . push ( suggest . label . substring ( previousEnd , start ) ) ;
791+ }
792+ // Add matching substring as bold text
793+ var end = start + length_1 ;
794+ var match = this . makeBold ( suggest . label . substring ( start , end ) ) ;
795+ parts . push ( match ) ;
796+ previousEnd = end ;
792797 }
793- if ( end < suggest . label . length ) {
794- post = suggest . label . slice ( end ) ;
798+ // Add non-matching substring after matches
799+ if ( previousEnd < suggest . label . length ) {
800+ parts . push ( suggest . label . substring ( previousEnd ) ) ;
795801 }
796- return ( React__namespace . createElement ( "span" , null ,
797- pre ,
798- boldPart ,
799- post ) ) ;
802+ return React__namespace . createElement ( "span" , null , parts ) ;
800803 } ;
801804 /**
802805 * Checking if item just became active and scrolling if needed.
@@ -1052,6 +1055,9 @@ var Geosuggest = (function (React) {
10521055 if ( ! this . state . ignoreBlur ) {
10531056 this . hideSuggests ( ) ;
10541057 }
1058+ if ( this . props . onBlur ) {
1059+ this . props . onBlur ( this . state . userInput ) ;
1060+ }
10551061 } ;
10561062 GeoSuggest . prototype . onNext = function ( ) {
10571063 this . activateSuggest ( 'next' ) ;
@@ -1178,10 +1184,12 @@ var Geosuggest = (function (React) {
11781184 ! skipSuggest ( fixture ) &&
11791185 fixture . label . match ( regex ) ) {
11801186 fixturesSearched ++ ;
1181- suggests . push ( __assign ( __assign ( { } , fixture ) , { isFixture : true , matchedSubstrings : {
1182- length : userInput . length ,
1183- offset : fixture . label . indexOf ( userInput )
1184- } , placeId : fixture . placeId || fixture . label } ) ) ;
1187+ suggests . push ( __assign ( __assign ( { } , fixture ) , { isFixture : true , matchedSubstrings : [
1188+ {
1189+ length : userInput . length ,
1190+ offset : fixture . label . search ( regex )
1191+ }
1192+ ] , placeId : fixture . placeId || fixture . label } ) ) ;
11851193 }
11861194 } ) ;
11871195 }
@@ -1193,7 +1201,7 @@ var Geosuggest = (function (React) {
11931201 label : _this . props . getSuggestLabel
11941202 ? _this . props . getSuggestLabel ( suggest )
11951203 : '' ,
1196- matchedSubstrings : suggest . matched_substrings [ 0 ] ,
1204+ matchedSubstrings : suggest . matched_substrings ,
11971205 placeId : suggest . place_id
11981206 } ) ;
11991207 }
@@ -1232,9 +1240,6 @@ var Geosuggest = (function (React) {
12321240 */
12331241 GeoSuggest . prototype . hideSuggests = function ( ) {
12341242 var _this = this ;
1235- if ( this . props . onBlur ) {
1236- this . props . onBlur ( this . state . userInput ) ;
1237- }
12381243 this . timer = window . setTimeout ( function ( ) {
12391244 _this . setState ( {
12401245 activeSuggest : null ,
0 commit comments