From f88dcd160c8857464c3bcf8f84d15f4440a02e19 Mon Sep 17 00:00:00 2001 From: Daniel Imms Date: Tue, 13 Jun 2017 19:49:12 -0700 Subject: [PATCH] Expose API on Terminal --- src/SearchHelper.ts | 7 ++++--- src/xterm.js | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/SearchHelper.ts b/src/SearchHelper.ts index 4a8631d1..65d82ecc 100644 --- a/src/SearchHelper.ts +++ b/src/SearchHelper.ts @@ -22,7 +22,7 @@ export class SearchHelper { */ public findNext(term: string): boolean { if (!term || term.length === 0) { - return; + return false; } let result: ISearchResult; @@ -63,7 +63,7 @@ export class SearchHelper { */ public findPrevious(term: string): boolean { if (!term || term.length === 0) { - return; + return false; } let result: ISearchResult; @@ -111,10 +111,11 @@ export class SearchHelper { private _selectResult(result: ISearchResult): boolean { if (!result) { - return; + return false; } this._terminal.selectionManager.setSelection(result.col, result.row, result.term.length); this._terminal.scrollDisp(result.row - this._terminal.ydisp, false); + return true; } // TODO: Consolidate with SelectionManager function diff --git a/src/xterm.js b/src/xterm.js index 789a7adf..8f2d64e3 100644 --- a/src/xterm.js +++ b/src/xterm.js @@ -1405,6 +1405,26 @@ Terminal.prototype.selectAll = function() { this.selectionManager.selectAll(); } +/** + * Find the next instance of the term, then scroll to and select it. If it + * doesn't exist, do nothing. + * @param term The term to search for. + * @return Whether a result was found. + */ +Terminal.prototype.findNext = function(term) { + return this.searchHelper.findNext(term); +} + +/** + * Find the previous instance of the term, then scroll to and select it. If it + * doesn't exist, do nothing. + * @param term The term to search for. + * @return Whether a result was found. + */ +Terminal.prototype.findPrevious = function(term) { + return this.searchHelper.findPrevious(term); +} + /** * Handle a keydown event * Key Resources: