Skip to content

Commit

Permalink
Disallow the empty string from being selected by find
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Sep 10, 2018
1 parent b2ba281 commit 5e004b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/addons/search/SearchHelper.ts
Expand Up @@ -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];
}
Expand Down
16 changes: 12 additions & 4 deletions src/addons/search/search.test.ts
Expand Up @@ -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(<any>MockTerminalPlain);
Expand All @@ -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(<any>MockTerminal);
const term = new MockTerminal({cols: 20, rows: 3});
term.core.write('Hello World\r\ntest\n123....hello');
Expand All @@ -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(<any>MockTerminal);
const term = new MockTerminal({cols: 10, rows: 5});
term.core.write('texttextHellotext\r\n');
Expand All @@ -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(<any>MockTerminal);
const term = new MockTerminal({cols: 10, rows: 4});
term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev ');
Expand Down Expand Up @@ -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(<any>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);
});
});
});

0 comments on commit 5e004b2

Please sign in to comment.