Skip to content

Commit

Permalink
Fixing error on multiple keyword highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch committed Nov 13, 2017
1 parent 3dc9997 commit 3360f3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Expand Up @@ -19,6 +19,10 @@ describe('HighlightedResultPipe', () => {
expect(pipe.transform('scams and flams', 'ams')).toBe('sc<mark>ams</mark> and fl<mark>ams</mark>');
});

it('should match multiple keywords', () => {
expect(pipe.transform('spam and eggs', 'spam eggs')).toBe('<mark>spam</mark> and <mark>eggs</mark>');
});

it('should coalesce adjacent matches', () => {
expect(pipe.transform('jeeepers', 'e')).toBe('j<mark>eee</mark>p<mark>e</mark>rs');
});
Expand Down
Expand Up @@ -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);
Expand Down

0 comments on commit 3360f3b

Please sign in to comment.