From 09028d4d86a4feb57935b61c213e1b88de3767e8 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 6 Sep 2018 11:36:36 -0700 Subject: [PATCH 1/8] Added support for searching accross wrapped lines --- src/Buffer.ts | 27 +++++++++ src/addons/search/SearchHelper.ts | 2 +- src/addons/search/search.test.ts | 92 +++++++++++++++++-------------- 3 files changed, 80 insertions(+), 41 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index 9487be4a67..f872b4855c 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -265,6 +265,33 @@ export class Buffer implements IBuffer { return lineString.substring(startIndex, endIndex); } + /** + * Translates a buffer line to a string, with optional start and end columns. + * Wide characters will count as two columns in the resulting string. This + * function is useful for getting the actual text underneath the raw selection + * position. + * @param line The line being translated. + * @param trimRight Whether to trim whitespace to the right. + */ + public translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string { + // Get full line + let lineString = ''; + let lineWrapsToNext = true; + if (this.lines.get(lineIndex).isWrapped) { + // This terminal line is a continuation of the previous line. + return ''; + } + + do { + lineString += this.translateBufferLineToString(lineIndex, true); + lineIndex++; + const nextLine = this.lines.get(lineIndex); + lineWrapsToNext = nextLine ? this.lines.get(lineIndex).isWrapped : false; + } while (lineWrapsToNext); + + return lineString; + } + public getWrappedRangeForLine(y: number): { first: number, last: number } { let first = y; let last = y; diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 63fd047b48..619845432f 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -107,7 +107,7 @@ export class SearchHelper implements ISearchHelper { * @return The search result if it was found. */ protected _findInLine(term: string, y: number, searchOptions: ISearchOptions = {}): ISearchResult { - const lowerStringLine = this._terminal._core.buffer.translateBufferLineToString(y, true).toLowerCase(); + const lowerStringLine = this._terminal._core.buffer.translateBufferLineToStringWithWrap(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); let searchIndex = -1; if (searchOptions.regex) { diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 8fcde95085..261fae5bac 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -40,45 +40,57 @@ describe('search addon', function(): void { assert.equal(typeof (MockTerminalPlain).prototype.findPrevious, 'function'); }); }); - it('Searchhelper - should find correct position', function(): void { - search.apply(MockTerminal); - const term = new MockTerminal({cols: 20, rows: 3}); - term.core.write('Hello World\r\ntest\n123....hello'); - term.pushWriteData(); - const hello0 = term.searchHelper.findInLine('Hello', 0); - const hello1 = term.searchHelper.findInLine('Hello', 1); - const hello2 = term.searchHelper.findInLine('Hello', 2); - expect(hello0).eql({col: 0, row: 0, term: 'Hello'}); - expect(hello1).eql(undefined); - expect(hello2).eql({col: 11, row: 2, term: 'Hello'}); - }); - it('should respect search regex', function(): void { - search.apply(MockTerminal); - const term = new MockTerminal({cols: 10, rows: 4}); - term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev '); - /* - abcdefghij - klmnopqrst - uvwxyz - ~/dev - */ - term.pushWriteData(); - const searchOptions = { - regex: true, - wholeWord: false, - caseSensitive: false - }; - const hello0 = term.searchHelper.findInLine('dee*', 0, searchOptions); - term.searchHelper.findInLine('jkk*', 0, searchOptions); - term.searchHelper.findInLine('mnn*', 1, searchOptions); - const tilda0 = term.searchHelper.findInLine('^~', 3, searchOptions); - const tilda1 = term.searchHelper.findInLine('^[~]', 3, searchOptions); - const tilda2 = term.searchHelper.findInLine('^\\~', 3, searchOptions); - expect(hello0).eql({col: 3, row: 0, term: 'de'}); - // TODO: uncomment this test when line wrap search is checked in expect(hello1).eql({col: 9, row: 0, term: 'jk'}); - // TODO: uncomment this test when line wrap search is checked in expect(hello2).eql(undefined); - expect(tilda0).eql({col: 0, row: 3, term: '~'}); - expect(tilda1).eql({col: 0, row: 3, term: '~'}); - expect(tilda2).eql({col: 0, row: 3, term: '~'}); + describe('find', () => { + it('Searchhelper - should find correct position', function(): void { + search.apply(MockTerminal); + const term = new MockTerminal({cols: 20, rows: 3}); + term.core.write('Hello World\r\ntest\n123....hello'); + term.pushWriteData(); + const hello0 = term.searchHelper.findInLine('Hello', 0); + const hello1 = term.searchHelper.findInLine('Hello', 1); + const hello2 = term.searchHelper.findInLine('Hello', 2); + expect(hello0).eql({col: 0, row: 0, term: 'Hello'}); + expect(hello1).eql(undefined); + expect(hello2).eql({col: 11, row: 2, term: 'Hello'}); + }); + it('should find search term accross line wrap', function(): void { + search.apply(MockTerminal); + const term = new MockTerminal({cols: 10, rows: 2}); + term.core.write('texttextHellotext'); + term.pushWriteData(); + const hello0 = (term.searchHelper as any)._findInLine('Hello', 0); + const hello1 = (term.searchHelper as any)._findInLine('Hello', 1); + expect(hello0).eql({col: 8, row: 0, term: 'Hello'}); + expect(hello1).eql(undefined); + }); + it('should respect search regex', function(): void { + search.apply(MockTerminal); + const term = new MockTerminal({cols: 10, rows: 4}); + term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev '); + /* + abcdefghij + klmnopqrst + uvwxyz + ~/dev + */ + term.pushWriteData(); + const searchOptions = { + regex: true, + wholeWord: false, + caseSensitive: false + }; + const hello0 = term.searchHelper.findInLine('dee*', 0, searchOptions); + const hello1 = term.searchHelper.findInLine('jkk*', 0, searchOptions); + const hello2 = term.searchHelper.findInLine('mnn*', 1, searchOptions); + const tilda0 = term.searchHelper.findInLine('^~', 3, searchOptions); + const tilda1 = term.searchHelper.findInLine('^[~]', 3, searchOptions); + const tilda2 = term.searchHelper.findInLine('^\\~', 3, searchOptions); + expect(hello0).eql({col: 3, row: 0, term: 'de'}); + expect(hello1).eql({col: 9, row: 0, term: 'jk'}); + expect(hello2).eql(undefined); + expect(tilda0).eql({col: 0, row: 3, term: '~'}); + expect(tilda1).eql({col: 0, row: 3, term: '~'}); + expect(tilda2).eql({col: 0, row: 3, term: '~'}); + }); }); }); From bc156294aa459f8b1fb07a402e43abfa03852ee7 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 6 Sep 2018 11:40:49 -0700 Subject: [PATCH 2/8] Udated comment --- src/Buffer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index f872b4855c..ad18dd0c55 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -266,7 +266,7 @@ export class Buffer implements IBuffer { } /** - * Translates a buffer line to a string, with optional start and end columns. + * Translates a buffer line to a string, including subsequent lines if they are wraps. * Wide characters will count as two columns in the resulting string. This * function is useful for getting the actual text underneath the raw selection * position. From 1460a3479620de5c705562da4ff72d80b11ebcd2 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 6 Sep 2018 13:53:03 -0700 Subject: [PATCH 3/8] Added another test case and fixed the multi-line issue that uncovered --- src/Buffer.ts | 7 +------ src/addons/search/SearchHelper.ts | 5 +++-- src/addons/search/search.test.ts | 10 ++++++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index ad18dd0c55..0cc2ee4dd0 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -274,13 +274,8 @@ export class Buffer implements IBuffer { * @param trimRight Whether to trim whitespace to the right. */ public translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string { - // Get full line let lineString = ''; - let lineWrapsToNext = true; - if (this.lines.get(lineIndex).isWrapped) { - // This terminal line is a continuation of the previous line. - return ''; - } + let lineWrapsToNext: boolean; do { lineString += this.translateBufferLineToString(lineIndex, true); diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 619845432f..89447da17b 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -120,8 +120,9 @@ export class SearchHelper implements ISearchHelper { } else { searchIndex = lowerStringLine.indexOf(lowerTerm); } - if (searchIndex >= 0) { - const line = this._terminal._core.buffer.lines.get(y); + + const line = this._terminal._core.buffer.lines.get(y); + if ((searchIndex >= 0) && (searchIndex < line.length)) { for (let i = 0; i < searchIndex; i++) { const charData = line.get(i); // Adjust the searchIndex to normalize emoji into single chars diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 261fae5bac..74f9cbc218 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -55,13 +55,19 @@ describe('search addon', function(): void { }); it('should find search term accross line wrap', function(): void { search.apply(MockTerminal); - const term = new MockTerminal({cols: 10, rows: 2}); - term.core.write('texttextHellotext'); + const term = new MockTerminal({cols: 10, rows: 5}); + term.core.write('texttextHellotext\r\n'); + term.core.write('texttexttextHellotext'); term.pushWriteData(); + const hello0 = (term.searchHelper as any)._findInLine('Hello', 0); const hello1 = (term.searchHelper as any)._findInLine('Hello', 1); + const hello2 = (term.searchHelper as any)._findInLine('Hello', 2); + const hello3 = (term.searchHelper as any)._findInLine('Hello', 3); expect(hello0).eql({col: 8, row: 0, term: 'Hello'}); expect(hello1).eql(undefined); + expect(hello2).eql(undefined); + expect(hello3).eql({col: 2, row: 3, term: 'Hello'}); }); it('should respect search regex', function(): void { search.apply(MockTerminal); From 54ed988fd17bface784d098d96184d8e03491936 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 7 Sep 2018 10:43:24 -0700 Subject: [PATCH 4/8] Fixed issues around searching lines twice and considering a wrapped line both it's own line and part of the previous line. --- src/Buffer.ts | 22 --------------- src/addons/search/SearchHelper.ts | 45 ++++++++++++++++++++++++++----- src/addons/search/search.test.ts | 13 +++++++-- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/Buffer.ts b/src/Buffer.ts index 0cc2ee4dd0..9487be4a67 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -265,28 +265,6 @@ export class Buffer implements IBuffer { return lineString.substring(startIndex, endIndex); } - /** - * Translates a buffer line to a string, including subsequent lines if they are wraps. - * Wide characters will count as two columns in the resulting string. This - * function is useful for getting the actual text underneath the raw selection - * position. - * @param line The line being translated. - * @param trimRight Whether to trim whitespace to the right. - */ - public translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string { - let lineString = ''; - let lineWrapsToNext: boolean; - - do { - lineString += this.translateBufferLineToString(lineIndex, true); - lineIndex++; - const nextLine = this.lines.get(lineIndex); - lineWrapsToNext = nextLine ? this.lines.get(lineIndex).isWrapped : false; - } while (lineWrapsToNext); - - return lineString; - } - public getWrappedRangeForLine(y: number): { first: number, last: number } { let first = y; let last = y; diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 89447da17b..0ee5ad12cd 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -100,15 +100,20 @@ export class SearchHelper implements ISearchHelper { } /** - * Searches a line for a search term. - * @param term The search term. + * Searches a line for a search term. Takes the provided terminal line and searches the text line, which may contain + * subsequent terminal lines if the text is wrapped. If the provided line number is part of a wrapped text line that + * started on an earlier line then it is skipped since it will be properly searched when the terminal line that the + * text starts on is searched. + * @param term Tne search term. * @param y The line to search. * @param searchOptions Search options. * @return The search result if it was found. */ protected _findInLine(term: string, y: number, searchOptions: ISearchOptions = {}): ISearchResult { - const lowerStringLine = this._terminal._core.buffer.translateBufferLineToStringWithWrap(y, true).toLowerCase(); - const lowerTerm = term.toLowerCase(); + if (this._terminal._core.buffer.lines.get(y).isWrapped) { + return; + } + const lowerStringLine = this.translateBufferLineToStringWithWrap(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); let searchIndex = -1; if (searchOptions.regex) { const searchRegex = RegExp(lowerTerm, 'g'); @@ -121,8 +126,14 @@ export class SearchHelper implements ISearchHelper { searchIndex = lowerStringLine.indexOf(lowerTerm); } - const line = this._terminal._core.buffer.lines.get(y); - if ((searchIndex >= 0) && (searchIndex < line.length)) { + if (searchIndex >= 0) { + // Adjust the row number and search index if needed since a "line" of text can span multiple rows + if (searchIndex >= this._terminal.cols) { + y += Math.floor(searchIndex / this._terminal.cols); + searchIndex = searchIndex % this._terminal.cols; + } + const line = this._terminal._core.buffer.lines.get(y); + for (let i = 0; i < searchIndex; i++) { const charData = line.get(i); // Adjust the searchIndex to normalize emoji into single chars @@ -145,6 +156,28 @@ export class SearchHelper implements ISearchHelper { } } + /** + * Translates a buffer line to a string, including subsequent lines if they are wraps. + * Wide characters will count as two columns in the resulting string. This + * function is useful for getting the actual text underneath the raw selection + * position. + * @param line The line being translated. + * @param trimRight Whether to trim whitespace to the right. + */ + public translateBufferLineToStringWithWrap(lineIndex: number, trimRight: boolean): string { + let lineString = ''; + let lineWrapsToNext: boolean; + + do { + lineString += this._terminal._core.buffer.translateBufferLineToString(lineIndex, true); + lineIndex++; + const nextLine = this._terminal._core.buffer.lines.get(lineIndex); + lineWrapsToNext = nextLine ? this._terminal._core.buffer.lines.get(lineIndex).isWrapped : false; + } while (lineWrapsToNext); + + return lineString; + } + /** * Selects and scrolls to a result. * @param result The result to select. diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 74f9cbc218..edf2a9f807 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -13,10 +13,19 @@ class MockTerminalPlain {} class MockTerminal { private _core: any; +<<<<<<< HEAD public searchHelper: TestSearchHelper; constructor(options: any) { this._core = new (require('../../../lib/Terminal').Terminal)(options); this.searchHelper = new TestSearchHelper(this as any); +======= + public searchHelper: ISearchHelper; + public cols: number; + constructor(options: any) { + this._core = new (require('../../../lib/Terminal').Terminal)(options); + this.searchHelper = new SearchHelper(this as any); + this.cols = options.cols; +>>>>>>> Fixed issues around searching lines twice and considering a wrapped line both it's own line and part of the previous line. } get core(): any { return this._core; @@ -66,8 +75,8 @@ describe('search addon', function(): void { const hello3 = (term.searchHelper as any)._findInLine('Hello', 3); expect(hello0).eql({col: 8, row: 0, term: 'Hello'}); expect(hello1).eql(undefined); - expect(hello2).eql(undefined); - expect(hello3).eql({col: 2, row: 3, term: 'Hello'}); + expect(hello2).eql({col: 2, row: 3, term: 'Hello'}); + expect(hello3).eql(undefined); }); it('should respect search regex', function(): void { search.apply(MockTerminal); From d5c17a0cc9fd7eb191d592689b31dc68b690d30a Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 7 Sep 2018 10:47:14 -0700 Subject: [PATCH 5/8] Added one more test case --- src/addons/search/search.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index edf2a9f807..2e0778e033 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -68,15 +68,24 @@ describe('search addon', function(): void { term.core.write('texttextHellotext\r\n'); term.core.write('texttexttextHellotext'); term.pushWriteData(); + /* + texttextHe + llotext + texttextte + xtHellotex + t + */ const hello0 = (term.searchHelper as any)._findInLine('Hello', 0); const hello1 = (term.searchHelper as any)._findInLine('Hello', 1); const hello2 = (term.searchHelper as any)._findInLine('Hello', 2); const hello3 = (term.searchHelper as any)._findInLine('Hello', 3); + const llo = (term.searchHelper as any)._findInLine('llo', 1); expect(hello0).eql({col: 8, row: 0, term: 'Hello'}); expect(hello1).eql(undefined); expect(hello2).eql({col: 2, row: 3, term: 'Hello'}); expect(hello3).eql(undefined); + expect(llo).eql(undefined); }); it('should respect search regex', function(): void { search.apply(MockTerminal); From bcf223e23599b1151cea93a19abd97d5494e3bfe Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Mon, 10 Sep 2018 10:43:03 -0700 Subject: [PATCH 6/8] Fixed merge errors --- src/addons/search/SearchHelper.ts | 3 ++- src/addons/search/search.test.ts | 9 +-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 0ee5ad12cd..207e566b01 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -113,7 +113,8 @@ export class SearchHelper implements ISearchHelper { if (this._terminal._core.buffer.lines.get(y).isWrapped) { return; } - const lowerStringLine = this.translateBufferLineToStringWithWrap(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); + const lowerStringLine = this.translateBufferLineToStringWithWrap(y, true).toLowerCase(); + const lowerTerm = term.toLowerCase(); let searchIndex = -1; if (searchOptions.regex) { const searchRegex = RegExp(lowerTerm, 'g'); diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 2e0778e033..747969308f 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -13,19 +13,12 @@ class MockTerminalPlain {} class MockTerminal { private _core: any; -<<<<<<< HEAD public searchHelper: TestSearchHelper; - constructor(options: any) { - this._core = new (require('../../../lib/Terminal').Terminal)(options); - this.searchHelper = new TestSearchHelper(this as any); -======= - public searchHelper: ISearchHelper; public cols: number; constructor(options: any) { this._core = new (require('../../../lib/Terminal').Terminal)(options); - this.searchHelper = new SearchHelper(this as any); + this.searchHelper = new TestSearchHelper(this as any); this.cols = options.cols; ->>>>>>> Fixed issues around searching lines twice and considering a wrapped line both it's own line and part of the previous line. } get core(): any { return this._core; From b2ba2819169982111abf573d08c27d155e9d6541 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 10 Sep 2018 12:09:26 -0700 Subject: [PATCH 7/8] Fix references in demo to addons --- demo/client.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/demo/client.ts b/demo/client.ts index 4af03548b6..099aab1411 100644 --- a/demo/client.ts +++ b/demo/client.ts @@ -8,12 +8,12 @@ /// import { Terminal } from '../lib/public/Terminal'; -import * as attach from '../build/addons/attach/attach'; -import * as fit from '../build/addons/fit/fit'; -import * as fullscreen from '../build/addons/fullscreen/fullscreen'; -import * as search from '../build/addons/search/search'; -import * as webLinks from '../build/addons/webLinks/webLinks'; -import * as winptyCompat from '../build/addons/winptyCompat/winptyCompat'; +import * as attach from '../lib/addons/attach/attach'; +import * as fit from '../lib/addons/fit/fit'; +import * as fullscreen from '../lib/addons/fullscreen/fullscreen'; +import * as search from '../lib/addons/search/search'; +import * as webLinks from '../lib/addons/webLinks/webLinks'; +import * as winptyCompat from '../lib/addons/winptyCompat/winptyCompat'; // Pulling in the module's types relies on the above, it's looks a // little weird here as we're importing "this" module From 5e004b21a3ac020768ff97347e7a636af184d10b Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Mon, 10 Sep 2018 12:13:48 -0700 Subject: [PATCH 8/8] Disallow the empty string from being selected by find --- src/addons/search/SearchHelper.ts | 2 +- src/addons/search/search.test.ts | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 207e566b01..4cc13e632e 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 747969308f..014b01d861 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); + }); }); });