diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 207e566b..4cc13e63 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -119,7 +119,7 @@ export class SearchHelper implements ISearchHelper { if (searchOptions.regex) { const searchRegex = RegExp(lowerTerm, 'g'); const foundTerm = searchRegex.exec(lowerStringLine); - if (foundTerm) { + if (foundTerm && foundTerm[0].length > 0) { searchIndex = searchRegex.lastIndex - foundTerm[0].length; term = foundTerm[0]; } diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 74796930..014b01d8 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -34,7 +34,7 @@ class TestSearchHelper extends SearchHelper { } } -describe('search addon', function(): void { +describe('search addon', () => { describe('apply', () => { it('should register findNext and findPrevious', () => { search.apply(MockTerminalPlain); @@ -43,7 +43,7 @@ describe('search addon', function(): void { }); }); describe('find', () => { - it('Searchhelper - should find correct position', function(): void { + it('Searchhelper - should find correct position', () => { search.apply(MockTerminal); const term = new MockTerminal({cols: 20, rows: 3}); term.core.write('Hello World\r\ntest\n123....hello'); @@ -55,7 +55,7 @@ describe('search addon', function(): void { expect(hello1).eql(undefined); expect(hello2).eql({col: 11, row: 2, term: 'Hello'}); }); - it('should find search term accross line wrap', function(): void { + it('should find search term accross line wrap', () => { search.apply(MockTerminal); const term = new MockTerminal({cols: 10, rows: 5}); term.core.write('texttextHellotext\r\n'); @@ -80,7 +80,7 @@ describe('search addon', function(): void { expect(hello3).eql(undefined); expect(llo).eql(undefined); }); - it('should respect search regex', function(): void { + it('should respect search regex', () => { search.apply(MockTerminal); const term = new MockTerminal({cols: 10, rows: 4}); term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev '); @@ -109,5 +109,13 @@ describe('search addon', function(): void { expect(tilda1).eql({col: 0, row: 3, term: '~'}); expect(tilda2).eql({col: 0, row: 3, term: '~'}); }); + it('should not select empty lines', () => { + search.apply(MockTerminal); + const term = new MockTerminal({cols: 20, rows: 3}); + term.core.write(' '); + term.pushWriteData(); + const line = term.searchHelper.findInLine('^.*$', 0, { regex: true }); + expect(line).eql(undefined); + }); }); });