@@ -300,24 +300,35 @@ angular.module('smartArea', [])
300
300
* a cssClass specified.
301
301
*/
302
302
function highlightText ( ) {
303
- var text = $scope . areaData ,
304
- html = htmlEncode ( text ) ;
303
+ var text = $scope . areaData ;
304
+ var cssClasses = [ ] ;
305
305
306
306
if ( typeof ( $scope . areaConfig . autocomplete ) === 'undefined' || $scope . areaConfig . autocomplete . length === 0 ) {
307
307
return ;
308
308
}
309
309
310
310
$scope . areaConfig . autocomplete . forEach ( function ( autoList ) {
311
311
for ( var i = 0 ; i < autoList . words . length ; i ++ ) {
312
+ var cssId = cssClasses . length ;
313
+ cssClasses . push ( autoList . cssClass ) ;
312
314
if ( typeof ( autoList . words [ i ] ) === "string" ) {
313
- html = html . replace ( new RegExp ( "([^\\w]|\\b)(" + autoList . words [ i ] + ")([^\\w]|\\b)" , 'g' ) , '$1<span class="' + autoList . cssClass + '">$2</span> $3') ;
315
+ text = text . replace ( new RegExp ( "([^\\w]|\\b)(" + autoList . words [ i ] + ")([^\\w]|\\b)" , 'g' ) , '$1§x' + cssId + 'x§$2§/x' + cssId + 'x§ $3') ;
314
316
} else {
315
- html = html . replace ( autoList . words [ i ] , function ( match ) {
316
- return '<span class="' + autoList . cssClass + '"> '+ match + '</span> ' ;
317
+ text = text . replace ( autoList . words [ i ] , function ( match ) {
318
+ return '§x' + cssId + 'x§ '+ match + '§/x' + cssId + 'x§ ';
317
319
} ) ;
318
320
}
319
321
}
320
322
} ) ;
323
+ var html = htmlEncode ( text ) ;
324
+ let changed ;
325
+ do {
326
+ changed = false ;
327
+ html = html . replace ( / § x ( \d + ) x § ( [ \s \S ] * ?) § \/ x \1x § / g, function ( match , cssId , content ) {
328
+ changed = true ;
329
+ return '<span class="' + cssClasses [ cssId ] + '">' + content + '</span>' ;
330
+ } ) ;
331
+ } while ( changed )
321
332
// Add to the fakeArea
322
333
$scope . fakeArea = $sce . trustAsHtml ( html ) ;
323
334
}
0 commit comments