From 1460a3479620de5c705562da4ff72d80b11ebcd2 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 6 Sep 2018 13:53:03 -0700 Subject: [PATCH] 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 ad18dd0c..0cc2ee4d 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 61984543..89447da1 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 261fae5b..74f9cbc2 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);