This commit is contained in:
Daniel Imms
2017-07-09 00:43:31 -07:00
parent fab039ddf3
commit 4b0cf2ffce
2 changed files with 18 additions and 4 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ declare var window: any;
/**
* 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.
* @param term Tne search term.
* @return Whether a result was found.
*/
Terminal.prototype.findNext = function(term: string): boolean {
@@ -45,7 +45,7 @@ declare var window: any;
/**
* 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.
* @param term Tne search term.
* @return Whether a result was found.
*/
Terminal.prototype.findPrevious = function(term: string): boolean {
+16 -2
View File
@@ -11,6 +11,9 @@ interface ISearchResult {
row: number;
}
/**
* A class that knows how to search the terminal and how to display the results.
*/
export class SearchHelper {
constructor(private _terminal: any, private _translateBufferLineToString: any) {
// TODO: Search for multiple instances on 1 line
@@ -22,7 +25,7 @@ export class SearchHelper {
/**
* 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.
* @param term Tne search term.
* @return Whether a result was found.
*/
public findNext(term: string): boolean {
@@ -63,7 +66,7 @@ export class SearchHelper {
/**
* 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.
* @param term Tne search term.
* @return Whether a result was found.
*/
public findPrevious(term: string): boolean {
@@ -101,6 +104,12 @@ export class SearchHelper {
return this._selectResult(result);
}
/**
* Searches a line for a search term.
* @param term Tne search term.
* @param y The line to search.
* @return The search result if it was found.
*/
private _findInLine(term: string, y: number): ISearchResult {
const bufferLine = this._terminal.lines.get(y);
const lowerStringLine = this._translateBufferLineToString(bufferLine, true).toLowerCase();
@@ -115,6 +124,11 @@ export class SearchHelper {
}
}
/**
* Selects and scrolls to a result.
* @param result The result to select.
* @return Whethera result was selected.
*/
private _selectResult(result: ISearchResult): boolean {
if (!result) {
return false;