From 88205511e62a83f23d677e07da7e55bd3ce391ea Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 7 Sep 2018 09:47:15 -0700 Subject: [PATCH 1/4] Added support for searching by regular expression --- demo/index.html | 1 + demo/main.js | 4 ++-- src/addons/search/Interfaces.ts | 4 ++-- src/addons/search/SearchHelper.ts | 28 ++++++++++++++++++++-------- src/addons/search/search.ts | 18 ++++++++++-------- 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/demo/index.html b/demo/index.html index fff77d0989..72804f465e 100644 --- a/demo/index.html +++ b/demo/index.html @@ -16,6 +16,7 @@

Actions

+

diff --git a/demo/main.js b/demo/main.js index 70544e38a2..79116efb59 100644 --- a/demo/main.js +++ b/demo/main.js @@ -83,13 +83,13 @@ function createTerminal() { addDomListener(actionElements.findNext, 'keypress', function (e) { if (e.key === "Enter") { e.preventDefault(); - term.findNext(actionElements.findNext.value); + term.findNext(actionElements.findNext.value, document.getElementById('regex').checked); } }); addDomListener(actionElements.findPrevious, 'keypress', function (e) { if (e.key === "Enter") { e.preventDefault(); - term.findPrevious(actionElements.findPrevious.value); + term.findPrevious(actionElements.findPrevious.value, document.getElementById('regex').checked); } }); diff --git a/src/addons/search/Interfaces.ts b/src/addons/search/Interfaces.ts index 926e3f36a3..e0ed11732f 100644 --- a/src/addons/search/Interfaces.ts +++ b/src/addons/search/Interfaces.ts @@ -17,6 +17,6 @@ export interface ISearchAddonTerminal extends Terminal { } export interface ISearchHelper { - findNext(term: string): boolean; - findPrevious(term: string): boolean; + findNext(term: string, regex: boolean): boolean; + findPrevious(term: string, regex: boolean): boolean; } diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 9b5c06f3be..0a22a57eb8 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -26,9 +26,10 @@ export class SearchHelper implements ISearchHelper { * Find the next instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. + * @param regex Should use regular expressions * @return Whether a result was found. */ - public findNext(term: string): boolean { + public findNext(term: string, regex: boolean = false): boolean { if (!term || term.length === 0) { return false; } @@ -43,7 +44,7 @@ export class SearchHelper implements ISearchHelper { // Search from ydisp + 1 to end for (let y = startRow + 1; y < this._terminal._core.buffer.ybase + this._terminal.rows; y++) { - result = this._findInLine(term, y); + result = this._findInLine(term, y, regex); if (result) { break; } @@ -52,7 +53,7 @@ export class SearchHelper implements ISearchHelper { // Search from the top to the current ydisp if (!result) { for (let y = 0; y < startRow; y++) { - result = this._findInLine(term, y); + result = this._findInLine(term, y, regex); if (result) { break; } @@ -67,9 +68,10 @@ export class SearchHelper implements ISearchHelper { * Find the previous instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. + * @param regex Should use regular expressions * @return Whether a result was found. */ - public findPrevious(term: string): boolean { + public findPrevious(term: string, regex: boolean = false): boolean { if (!term || term.length === 0) { return false; } @@ -84,7 +86,7 @@ export class SearchHelper implements ISearchHelper { // Search from ydisp + 1 to end for (let y = startRow - 1; y >= 0; y--) { - result = this._findInLine(term, y); + result = this._findInLine(term, y, regex); if (result) { break; } @@ -93,7 +95,7 @@ export class SearchHelper implements ISearchHelper { // Search from the top to the current ydisp if (!result) { for (let y = this._terminal._core.buffer.ybase + this._terminal.rows - 1; y > startRow; y--) { - result = this._findInLine(term, y); + result = this._findInLine(term, y, regex); if (result) { break; } @@ -108,12 +110,22 @@ export class SearchHelper implements ISearchHelper { * Searches a line for a search term. * @param term Tne search term. * @param y The line to search. + * @param regex Should use regular expressions * @return The search result if it was found. */ - private _findInLine(term: string, y: number): ISearchResult { + private _findInLine(term: string, y: number, regex: boolean): ISearchResult { const lowerStringLine = this._terminal._core.buffer.translateBufferLineToString(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); - let searchIndex = lowerStringLine.indexOf(lowerTerm); + let searchIndex = -1; + if (regex) { + const searchRegex = RegExp(lowerTerm, 'g'); + const foundTerm = searchRegex.exec(lowerStringLine); + if (foundTerm) { + searchIndex = searchRegex.lastIndex - foundTerm[0].length; + } + } else { + searchIndex = lowerStringLine.indexOf(lowerTerm); + } if (searchIndex >= 0) { const line = this._terminal._core.buffer.lines.get(y); for (let i = 0; i < searchIndex; i++) { diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index a1dd766ffd..4e97dd903c 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -11,36 +11,38 @@ import { ISearchAddonTerminal } from './Interfaces'; * Find the next instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. + * @param regex Should use regular expressions * @return Whether a result was found. */ -export function findNext(terminal: Terminal, term: string): boolean { +export function findNext(terminal: Terminal, term: string, regex: boolean): boolean { const addonTerminal = terminal; if (!addonTerminal.__searchHelper) { addonTerminal.__searchHelper = new SearchHelper(addonTerminal); } - return addonTerminal.__searchHelper.findNext(term); + return addonTerminal.__searchHelper.findNext(term, regex); } /** * Find the previous instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. + * @param regex Should use regular expressions * @return Whether a result was found. */ -export function findPrevious(terminal: Terminal, term: string): boolean { +export function findPrevious(terminal: Terminal, term: string, regex: boolean): boolean { const addonTerminal = terminal; if (!addonTerminal.__searchHelper) { addonTerminal.__searchHelper = new SearchHelper(addonTerminal); } - return addonTerminal.__searchHelper.findPrevious(term); + return addonTerminal.__searchHelper.findPrevious(term, regex); } export function apply(terminalConstructor: typeof Terminal): void { - (terminalConstructor.prototype).findNext = function(term: string): boolean { - return findNext(this, term); + (terminalConstructor.prototype).findNext = function(term: string, regex: boolean): boolean { + return findNext(this, term, regex); }; - (terminalConstructor.prototype).findPrevious = function(term: string): boolean { - return findPrevious(this, term); + (terminalConstructor.prototype).findPrevious = function(term: string, regex: boolean): boolean { + return findPrevious(this, term, regex); }; } From 03e54cce7d289bc198a2cc5caaa50e91558abfc9 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 7 Sep 2018 11:01:08 -0700 Subject: [PATCH 2/4] Added regex search test --- src/addons/search/search.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 91ecc4efbd..891418f400 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -46,4 +46,21 @@ describe('search addon', function(): void { 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: 3}); + term.core.write('abcdefghijklmnopqrstuvwxyz'); + /* + abcdefghij + klmnopqrst + uvwxyz + */ + term.pushWriteData(); + const hello0 = (term.searchHelper as any)._findInLine('dee*', 0, true); + const hello1 = (term.searchHelper as any)._findInLine('jkk*', 0, true); + const hello2 = (term.searchHelper as any)._findInLine('mnn*', 1, true); + expect(hello0).eql({col: 3, row: 0, term: 'dee*'}); + // TODO: uncomment this test when line wrap search is checked in expect(hello1).eql({col: 9, row: 0, term: 'jkk*'}); + // TODO: uncomment this test when line wrap search is checked in expect(hello2).eql(undefined); + }); }); From e5465841f8de0e89222b4a6827d51f6e19fcf655 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 7 Sep 2018 15:29:51 -0700 Subject: [PATCH 3/4] Responded to feedback and fixed the returned found term --- demo/main.js | 14 ++++++++++++-- src/addons/search/Interfaces.ts | 10 ++++++++-- src/addons/search/SearchHelper.ts | 28 ++++++++++++++-------------- src/addons/search/search.test.ts | 26 +++++++++++++++++++------- src/addons/search/search.ts | 22 +++++++++++----------- 5 files changed, 64 insertions(+), 36 deletions(-) diff --git a/demo/main.js b/demo/main.js index 79116efb59..12537db201 100644 --- a/demo/main.js +++ b/demo/main.js @@ -83,13 +83,23 @@ function createTerminal() { addDomListener(actionElements.findNext, 'keypress', function (e) { if (e.key === "Enter") { e.preventDefault(); - term.findNext(actionElements.findNext.value, document.getElementById('regex').checked); + let searchOptions = { + regex: document.getElementById('regex').checked, + wholeWord: false, + caseSensitive: false + }; + term.findNext(actionElements.findNext.value, searchOptions); } }); addDomListener(actionElements.findPrevious, 'keypress', function (e) { if (e.key === "Enter") { e.preventDefault(); - term.findPrevious(actionElements.findPrevious.value, document.getElementById('regex').checked); + let searchOptions = { + regex: document.getElementById('regex').checked, + wholeWord: false, + caseSensitive: false + }; + term.findPrevious(actionElements.findPrevious.value, searchOptions); } }); diff --git a/src/addons/search/Interfaces.ts b/src/addons/search/Interfaces.ts index e0ed11732f..4fa8b77e6b 100644 --- a/src/addons/search/Interfaces.ts +++ b/src/addons/search/Interfaces.ts @@ -17,6 +17,12 @@ export interface ISearchAddonTerminal extends Terminal { } export interface ISearchHelper { - findNext(term: string, regex: boolean): boolean; - findPrevious(term: string, regex: boolean): boolean; + findNext(term: string, searchOptions: ISearchOptions): boolean; + findPrevious(term: string, searchOptions: ISearchOptions): boolean; +} + +export interface ISearchOptions { + regex: boolean; + wholeWord: boolean; + caseSensitive: boolean; } diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index 0a22a57eb8..be1a1475d5 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { ISearchHelper, ISearchAddonTerminal } from './Interfaces'; +import { ISearchHelper, ISearchAddonTerminal, ISearchOptions } from './Interfaces'; interface ISearchResult { term: string; @@ -19,17 +19,16 @@ export class SearchHelper implements ISearchHelper { // TODO: Search for multiple instances on 1 line // TODO: Don't use the actual selection, instead use a "find selection" so multiple instances can be highlighted // TODO: Highlight other instances in the viewport - // TODO: Support regex, case sensitivity, etc. } /** * Find the next instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. - * @param regex Should use regular expressions + * @param searchOptions Search options. * @return Whether a result was found. */ - public findNext(term: string, regex: boolean = false): boolean { + public findNext(term: string, searchOptions: ISearchOptions): boolean { if (!term || term.length === 0) { return false; } @@ -44,7 +43,7 @@ export class SearchHelper implements ISearchHelper { // Search from ydisp + 1 to end for (let y = startRow + 1; y < this._terminal._core.buffer.ybase + this._terminal.rows; y++) { - result = this._findInLine(term, y, regex); + result = this._findInLine(term, y, searchOptions); if (result) { break; } @@ -53,7 +52,7 @@ export class SearchHelper implements ISearchHelper { // Search from the top to the current ydisp if (!result) { for (let y = 0; y < startRow; y++) { - result = this._findInLine(term, y, regex); + result = this._findInLine(term, y, searchOptions); if (result) { break; } @@ -68,10 +67,10 @@ export class SearchHelper implements ISearchHelper { * Find the previous instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. - * @param regex Should use regular expressions + * @param searchOptions Search options. * @return Whether a result was found. */ - public findPrevious(term: string, regex: boolean = false): boolean { + public findPrevious(term: string, searchOptions: ISearchOptions): boolean { if (!term || term.length === 0) { return false; } @@ -86,7 +85,7 @@ export class SearchHelper implements ISearchHelper { // Search from ydisp + 1 to end for (let y = startRow - 1; y >= 0; y--) { - result = this._findInLine(term, y, regex); + result = this._findInLine(term, y, searchOptions); if (result) { break; } @@ -95,7 +94,7 @@ export class SearchHelper implements ISearchHelper { // Search from the top to the current ydisp if (!result) { for (let y = this._terminal._core.buffer.ybase + this._terminal.rows - 1; y > startRow; y--) { - result = this._findInLine(term, y, regex); + result = this._findInLine(term, y, searchOptions); if (result) { break; } @@ -108,20 +107,21 @@ export class SearchHelper implements ISearchHelper { /** * Searches a line for a search term. - * @param term Tne search term. + * @param term The search term. * @param y The line to search. - * @param regex Should use regular expressions + * @param searchOptions Search options. * @return The search result if it was found. */ - private _findInLine(term: string, y: number, regex: boolean): ISearchResult { + private _findInLine(term: string, y: number, searchOptions: ISearchOptions = {regex: false, wholeWord: false, caseSensitive: false}): ISearchResult { const lowerStringLine = this._terminal._core.buffer.translateBufferLineToString(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); let searchIndex = -1; - if (regex) { + if (searchOptions.regex) { const searchRegex = RegExp(lowerTerm, 'g'); const foundTerm = searchRegex.exec(lowerStringLine); if (foundTerm) { searchIndex = searchRegex.lastIndex - foundTerm[0].length; + term = foundTerm[0]; } } else { searchIndex = lowerStringLine.indexOf(lowerTerm); diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 891418f400..9616ae3ce0 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -48,19 +48,31 @@ describe('search addon', function(): void { }); it('should respect search regex', function(): void { search.apply(MockTerminal); - const term = new MockTerminal({cols: 10, rows: 3}); - term.core.write('abcdefghijklmnopqrstuvwxyz'); + const term = new MockTerminal({cols: 10, rows: 4}); + term.core.write('abcdefghijklmnopqrstuvwxyz\r\n~/dev '); /* abcdefghij klmnopqrst uvwxyz + ~/dev */ term.pushWriteData(); - const hello0 = (term.searchHelper as any)._findInLine('dee*', 0, true); - const hello1 = (term.searchHelper as any)._findInLine('jkk*', 0, true); - const hello2 = (term.searchHelper as any)._findInLine('mnn*', 1, true); - expect(hello0).eql({col: 3, row: 0, term: 'dee*'}); - // TODO: uncomment this test when line wrap search is checked in expect(hello1).eql({col: 9, row: 0, term: 'jkk*'}); + const searchOptions = { + regex: true, + wholeWord: false, + caseSensitive: false + }; + const hello0 = (term.searchHelper as any)._findInLine('dee*', 0, searchOptions); + const hello1 = (term.searchHelper as any)._findInLine('jkk*', 0, searchOptions); + const hello2 = (term.searchHelper as any)._findInLine('mnn*', 1, searchOptions); + const tilda0 = (term.searchHelper as any)._findInLine('^~', 3, searchOptions); + const tilda1 = (term.searchHelper as any)._findInLine('^[~]', 3, searchOptions); + const tilda2 = (term.searchHelper as any)._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: '~'}); }); }); diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index 4e97dd903c..93ac88436c 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -5,44 +5,44 @@ import { SearchHelper } from './SearchHelper'; import { Terminal } from 'xterm'; -import { ISearchAddonTerminal } from './Interfaces'; +import { ISearchAddonTerminal, ISearchOptions } from './Interfaces'; /** * Find the next instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. - * @param regex Should use regular expressions + * @param searchOptions Search options * @return Whether a result was found. */ -export function findNext(terminal: Terminal, term: string, regex: boolean): boolean { +export function findNext(terminal: Terminal, term: string, searchOptions: ISearchOptions = {regex: false, wholeWord: false, caseSensitive: false}): boolean { const addonTerminal = terminal; if (!addonTerminal.__searchHelper) { addonTerminal.__searchHelper = new SearchHelper(addonTerminal); } - return addonTerminal.__searchHelper.findNext(term, regex); + return addonTerminal.__searchHelper.findNext(term, searchOptions); } /** * Find the previous instance of the term, then scroll to and select it. If it * doesn't exist, do nothing. * @param term Tne search term. - * @param regex Should use regular expressions + * @param searchOptions Search options * @return Whether a result was found. */ -export function findPrevious(terminal: Terminal, term: string, regex: boolean): boolean { +export function findPrevious(terminal: Terminal, term: string, searchOptions: ISearchOptions = {regex: false, wholeWord: false, caseSensitive: false}): boolean { const addonTerminal = terminal; if (!addonTerminal.__searchHelper) { addonTerminal.__searchHelper = new SearchHelper(addonTerminal); } - return addonTerminal.__searchHelper.findPrevious(term, regex); + return addonTerminal.__searchHelper.findPrevious(term, searchOptions); } export function apply(terminalConstructor: typeof Terminal): void { - (terminalConstructor.prototype).findNext = function(term: string, regex: boolean): boolean { - return findNext(this, term, regex); + (terminalConstructor.prototype).findNext = function(term: string, searchOptions: ISearchOptions): boolean { + return findNext(this, term, searchOptions); }; - (terminalConstructor.prototype).findPrevious = function(term: string, regex: boolean): boolean { - return findPrevious(this, term, regex); + (terminalConstructor.prototype).findPrevious = function(term: string, searchOptions: ISearchOptions): boolean { + return findPrevious(this, term, searchOptions); }; } From 599271bde462a8ae5eeabab01baec552c9a67999 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Sat, 8 Sep 2018 02:10:02 -0700 Subject: [PATCH 4/4] Make search option props optional, test optional typings --- src/addons/search/Interfaces.ts | 12 +++++++++--- src/addons/search/SearchHelper.ts | 14 ++++---------- src/addons/search/search.test.ts | 30 ++++++++++++++++++------------ src/addons/search/search.ts | 4 ++-- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/addons/search/Interfaces.ts b/src/addons/search/Interfaces.ts index 4fa8b77e6b..af06c5d1ad 100644 --- a/src/addons/search/Interfaces.ts +++ b/src/addons/search/Interfaces.ts @@ -22,7 +22,13 @@ export interface ISearchHelper { } export interface ISearchOptions { - regex: boolean; - wholeWord: boolean; - caseSensitive: boolean; + regex?: boolean; + wholeWord?: boolean; + caseSensitive?: boolean; +} + +export interface ISearchResult { + term: string; + col: number; + row: number; } diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts index be1a1475d5..63fd047b48 100644 --- a/src/addons/search/SearchHelper.ts +++ b/src/addons/search/SearchHelper.ts @@ -3,13 +3,7 @@ * @license MIT */ -import { ISearchHelper, ISearchAddonTerminal, ISearchOptions } from './Interfaces'; - -interface ISearchResult { - term: string; - col: number; - row: number; -} +import { ISearchHelper, ISearchAddonTerminal, ISearchOptions, ISearchResult } from './Interfaces'; /** * A class that knows how to search the terminal and how to display the results. @@ -28,7 +22,7 @@ export class SearchHelper implements ISearchHelper { * @param searchOptions Search options. * @return Whether a result was found. */ - public findNext(term: string, searchOptions: ISearchOptions): boolean { + public findNext(term: string, searchOptions?: ISearchOptions): boolean { if (!term || term.length === 0) { return false; } @@ -70,7 +64,7 @@ export class SearchHelper implements ISearchHelper { * @param searchOptions Search options. * @return Whether a result was found. */ - public findPrevious(term: string, searchOptions: ISearchOptions): boolean { + public findPrevious(term: string, searchOptions?: ISearchOptions): boolean { if (!term || term.length === 0) { return false; } @@ -112,7 +106,7 @@ export class SearchHelper implements ISearchHelper { * @param searchOptions Search options. * @return The search result if it was found. */ - private _findInLine(term: string, y: number, searchOptions: ISearchOptions = {regex: false, wholeWord: false, caseSensitive: false}): ISearchResult { + protected _findInLine(term: string, y: number, searchOptions: ISearchOptions = {}): ISearchResult { const lowerStringLine = this._terminal._core.buffer.translateBufferLineToString(y, true).toLowerCase(); const lowerTerm = term.toLowerCase(); let searchIndex = -1; diff --git a/src/addons/search/search.test.ts b/src/addons/search/search.test.ts index 9616ae3ce0..8fcde95085 100644 --- a/src/addons/search/search.test.ts +++ b/src/addons/search/search.test.ts @@ -6,17 +6,17 @@ import { assert, expect } from 'chai'; import * as search from './search'; import { SearchHelper } from './SearchHelper'; -import { ISearchHelper } from './Interfaces'; +import { ISearchOptions, ISearchResult } from './Interfaces'; class MockTerminalPlain {} class MockTerminal { private _core: any; - public searchHelper: ISearchHelper; + public searchHelper: TestSearchHelper; 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); } get core(): any { return this._core; @@ -26,6 +26,12 @@ class MockTerminal { } } +class TestSearchHelper extends SearchHelper { + public findInLine(term: string, y: number, searchOptions?: ISearchOptions): ISearchResult { + return this._findInLine(term, y, searchOptions); + } +} + describe('search addon', function(): void { describe('apply', () => { it('should register findNext and findPrevious', () => { @@ -39,9 +45,9 @@ describe('search addon', function(): void { const term = new MockTerminal({cols: 20, rows: 3}); term.core.write('Hello World\r\ntest\n123....hello'); 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 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'}); @@ -62,12 +68,12 @@ describe('search addon', function(): void { wholeWord: false, caseSensitive: false }; - const hello0 = (term.searchHelper as any)._findInLine('dee*', 0, searchOptions); - const hello1 = (term.searchHelper as any)._findInLine('jkk*', 0, searchOptions); - const hello2 = (term.searchHelper as any)._findInLine('mnn*', 1, searchOptions); - const tilda0 = (term.searchHelper as any)._findInLine('^~', 3, searchOptions); - const tilda1 = (term.searchHelper as any)._findInLine('^[~]', 3, searchOptions); - const tilda2 = (term.searchHelper as any)._findInLine('^\\~', 3, searchOptions); + 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); diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts index 93ac88436c..9be0b33b53 100644 --- a/src/addons/search/search.ts +++ b/src/addons/search/search.ts @@ -14,7 +14,7 @@ import { ISearchAddonTerminal, ISearchOptions } from './Interfaces'; * @param searchOptions Search options * @return Whether a result was found. */ -export function findNext(terminal: Terminal, term: string, searchOptions: ISearchOptions = {regex: false, wholeWord: false, caseSensitive: false}): boolean { +export function findNext(terminal: Terminal, term: string, searchOptions: ISearchOptions = {}): boolean { const addonTerminal = terminal; if (!addonTerminal.__searchHelper) { addonTerminal.__searchHelper = new SearchHelper(addonTerminal); @@ -29,7 +29,7 @@ export function findNext(terminal: Terminal, term: string, searchOptions: ISearc * @param searchOptions Search options * @return Whether a result was found. */ -export function findPrevious(terminal: Terminal, term: string, searchOptions: ISearchOptions = {regex: false, wholeWord: false, caseSensitive: false}): boolean { +export function findPrevious(terminal: Terminal, term: string, searchOptions: ISearchOptions): boolean { const addonTerminal = terminal; if (!addonTerminal.__searchHelper) { addonTerminal.__searchHelper = new SearchHelper(addonTerminal);