diff --git a/src/addons/search/Interfaces.ts b/src/addons/search/Interfaces.ts
new file mode 100644
index 000000000..7a7a87cc7
--- /dev/null
+++ b/src/addons/search/Interfaces.ts
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2018 The xterm.js authors. All rights reserved.
+ * @license MIT
+ */
+
+import { Terminal } from 'xterm';
+
+export interface ISearchAddonTerminal extends Terminal {
+ __searchHelper: ISearchHelper;
+
+ // TODO: Reuse ITerminal from core
+ buffer: any;
+ selectionManager: any;
+}
+
+export interface ISearchHelper {
+ findNext(term: string): boolean;
+ findPrevious(term: string): boolean;
+}
diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts
index 5735dd48e..dd941682a 100644
--- a/src/addons/search/SearchHelper.ts
+++ b/src/addons/search/SearchHelper.ts
@@ -3,8 +3,7 @@
* @license MIT
*/
-// import { ITerminal } from '../../Interfaces';
-// import { translateBufferLineToString } from '../../utils/BufferLine';
+import { ISearchHelper, ISearchAddonTerminal } from './Interfaces';
interface ISearchResult {
term: string;
@@ -15,8 +14,8 @@ interface ISearchResult {
/**
* A class that knows how to search the terminal and how to display the results.
*/
-export class SearchHelper {
- constructor(private _terminal: any) {
+export class SearchHelper implements ISearchHelper {
+ constructor(private _terminal: ISearchAddonTerminal) {
// 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
@@ -134,7 +133,7 @@ export class SearchHelper {
return false;
}
this._terminal.selectionManager.setSelection(result.col, result.row, result.term.length);
- this._terminal.scrollLines(result.row - this._terminal.buffer.ydisp, false);
+ this._terminal.scrollLines(result.row - this._terminal.buffer.ydisp);
return true;
}
}
diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts
index 473c78fcf..2f5db9224 100644
--- a/src/addons/search/search.ts
+++ b/src/addons/search/search.ts
@@ -3,8 +3,11 @@
* @license MIT
*/
-import { SearchHelper } from './SearchHelper';
+///
+import { SearchHelper } from './SearchHelper';
+import { Terminal } from 'xterm';
+import { ISearchAddonTerminal } from './Interfaces';
/**
* Find the next instance of the term, then scroll to and select it. If it
@@ -12,11 +15,12 @@ import { SearchHelper } from './SearchHelper';
* @param term Tne search term.
* @return Whether a result was found.
*/
-export function findNext(terminal: any, term: string): boolean {
- if (!terminal._searchHelper) {
- terminal.searchHelper = new SearchHelper(terminal);
+export function findNext(terminal: Terminal, term: string): boolean {
+ const addonTerminal = (terminal);
+ if (!addonTerminal.__searchHelper) {
+ addonTerminal.__searchHelper = new SearchHelper(addonTerminal);
}
- return (terminal.searchHelper).findNext(term);
+ return addonTerminal.__searchHelper.findNext(term);
}
/**
@@ -25,19 +29,20 @@ export function findNext(terminal: any, term: string): boolean {
* @param term Tne search term.
* @return Whether a result was found.
*/
-export function findPrevious(terminal: any, term: string): boolean {
- if (!terminal._searchHelper) {
- terminal.searchHelper = new SearchHelper(terminal);
+export function findPrevious(terminal: Terminal, term: string): boolean {
+ const addonTerminal = (terminal);
+ if (!addonTerminal.__searchHelper) {
+ addonTerminal.__searchHelper = new SearchHelper(addonTerminal);
}
- return (terminal.searchHelper).findPrevious(term);
+ return addonTerminal.__searchHelper.findPrevious(term);
}
export function apply(terminalConstructor: any): void {
- terminalConstructor.prototype.findNext = function(term: any): boolean {
+ terminalConstructor.prototype.findNext = function(term: string): boolean {
return findNext(this, term);
};
- terminalConstructor.prototype.findPrevious = function(term: any): boolean {
+ terminalConstructor.prototype.findPrevious = function(term: string): boolean {
return findPrevious(this, term);
};
}