Disallow the empty string from being selected by find

This commit is contained in:
Daniel Imms
2018-09-10 12:17:17 -07:00
parent b2ba281916
commit 5e004b21a3
2 changed files with 13 additions and 5 deletions
+1 -1
View File
@@ -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];
}
+12 -4
View File
@@ -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);
@@ -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');
@@ -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');
@@ -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 ');
@@ -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);
});
});
});