From 3360f3bdd9dc312b81b2270d6c65a3fbd6c7d54a Mon Sep 17 00:00:00 2001 From: Michael Lynch Date: Mon, 13 Nov 2017 10:03:56 -0500 Subject: [PATCH] Fixing error on multiple keyword highlight --- .../_pipes/highlighted-result/highlighted-result.pipe.spec.ts | 4 ++++ src/app/_pipes/highlighted-result/highlighted-result.pipe.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/_pipes/highlighted-result/highlighted-result.pipe.spec.ts b/src/app/_pipes/highlighted-result/highlighted-result.pipe.spec.ts index 00cde76..42df3e1 100644 --- a/src/app/_pipes/highlighted-result/highlighted-result.pipe.spec.ts +++ b/src/app/_pipes/highlighted-result/highlighted-result.pipe.spec.ts @@ -19,6 +19,10 @@ describe('HighlightedResultPipe', () => { expect(pipe.transform('scams and flams', 'ams')).toBe('scams and flams'); }); + it('should match multiple keywords', () => { + expect(pipe.transform('spam and eggs', 'spam eggs')).toBe('spam and eggs'); + }); + it('should coalesce adjacent matches', () => { expect(pipe.transform('jeeepers', 'e')).toBe('jeeepers'); }); diff --git a/src/app/_pipes/highlighted-result/highlighted-result.pipe.ts b/src/app/_pipes/highlighted-result/highlighted-result.pipe.ts index 727fce7..7dc6dc7 100644 --- a/src/app/_pipes/highlighted-result/highlighted-result.pipe.ts +++ b/src/app/_pipes/highlighted-result/highlighted-result.pipe.ts @@ -11,7 +11,7 @@ export class HighlightedResultPipe implements PipeTransform { if (keywords && highlightedValue) { for (const keyword of keywords.split(' ')) { let startIndex = 0; - startIndex = value.toLowerCase().indexOf(keyword.toLowerCase()); + startIndex = highlightedValue.toLowerCase().indexOf(keyword.toLowerCase()); while (startIndex !== -1) { const endLength = keyword.length; const matchingString = highlightedValue.substr(startIndex, endLength);