]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Change case of search addon files
authorDaniel Imms <daimms@microsoft.com>
Sun, 9 Jul 2017 07:55:50 +0000 (00:55 -0700)
committerDaniel Imms <daimms@microsoft.com>
Sun, 9 Jul 2017 07:55:50 +0000 (00:55 -0700)
src/addons/search/Search.ts [new file with mode: 0644]
src/addons/search/SearchHelper.ts [new file with mode: 0644]
src/addons/search/search.ts [deleted file]
src/addons/search/searchHelper.ts [deleted file]

diff --git a/src/addons/search/Search.ts b/src/addons/search/Search.ts
new file mode 100644 (file)
index 0000000..5a227a8
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * @license MIT
+ */
+
+import { SearchHelper } from './SearchHelper';
+
+declare var exports: any;
+declare var module: any;
+declare var define: any;
+declare var require: any;
+declare var window: any;
+
+(function (addon) {
+  if ('Terminal' in window) {
+    /**
+     * Plain browser environment
+     */
+    addon(window.Terminal);
+  } else if (typeof exports === 'object' && typeof module === 'object') {
+    /**
+     * CommonJS environment
+     */
+    const xterm = '../../xterm';
+    module.exports = addon(require(xterm));
+  } else if (typeof define == 'function') {
+    /**
+     * Require.js is available
+     */
+    define(['../../xterm'], addon);
+  }
+})((Terminal: any) => {
+  /**
+   * 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.
+   * @return Whether a result was found.
+   */
+  Terminal.prototype.findNext = function(term: string): boolean {
+    if (!this._searchHelper) {
+      this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString);
+    }
+    return (<SearchHelper>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 Tne search term.
+   * @return Whether a result was found.
+   */
+  Terminal.prototype.findPrevious = function(term: string): boolean {
+    if (!this._searchHelper) {
+      this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString);
+    }
+    return (<SearchHelper>this.searchHelper).findPrevious(term);
+  };
+});
diff --git a/src/addons/search/SearchHelper.ts b/src/addons/search/SearchHelper.ts
new file mode 100644 (file)
index 0000000..f285144
--- /dev/null
@@ -0,0 +1,140 @@
+/**
+ * @license MIT
+ */
+
+// import { ITerminal } from '../../Interfaces';
+// import { translateBufferLineToString } from '../../utils/BufferLine';
+
+interface ISearchResult {
+  term: string;
+  col: number;
+  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
+    // 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.
+   * @return Whether a result was found.
+   */
+  public findNext(term: string): boolean {
+    if (!term || term.length === 0) {
+      return false;
+    }
+
+    let result: ISearchResult;
+
+    let startRow = this._terminal.ydisp;
+    if (this._terminal.selectionManager.selectionEnd) {
+      // Start from the selection end if there is a selection
+      startRow = this._terminal.selectionManager.selectionEnd[1];
+    }
+
+    // Search from ydisp + 1 to end
+    for (let y = startRow + 1; y < this._terminal.ybase + this._terminal.rows; y++) {
+      result = this._findInLine(term, y);
+      if (result) {
+        break;
+      }
+    }
+
+    // Search from the top to the current ydisp
+    if (!result) {
+      for (let y = 0; y < startRow; y++) {
+        result = this._findInLine(term, y);
+        if (result) {
+          break;
+        }
+      }
+    }
+
+    // Set selection and scroll if a result was found
+    return this._selectResult(result);
+  }
+
+  /**
+   * 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.
+   * @return Whether a result was found.
+   */
+  public findPrevious(term: string): boolean {
+    if (!term || term.length === 0) {
+      return false;
+    }
+
+    let result: ISearchResult;
+
+    let startRow = this._terminal.ydisp;
+    if (this._terminal.selectionManager.selectionStart) {
+      // Start from the selection end if there is a selection
+      startRow = this._terminal.selectionManager.selectionStart[1];
+    }
+
+    // Search from ydisp + 1 to end
+    for (let y = startRow - 1; y >= 0; y--) {
+      result = this._findInLine(term, y);
+      if (result) {
+        break;
+      }
+    }
+
+    // Search from the top to the current ydisp
+    if (!result) {
+      for (let y = this._terminal.ybase + this._terminal.rows - 1; y > startRow; y--) {
+        result = this._findInLine(term, y);
+        if (result) {
+          break;
+        }
+      }
+    }
+
+    // Set selection and scroll if a result was found
+    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();
+    const lowerTerm = term.toLowerCase();
+    const searchIndex = lowerStringLine.indexOf(lowerTerm);
+    if (searchIndex >= 0) {
+      return {
+        term,
+        col: searchIndex,
+        row: y
+      };
+    }
+  }
+
+  /**
+   * 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;
+    }
+    this._terminal.selectionManager.setSelection(result.col, result.row, result.term.length);
+    this._terminal.scrollDisp(result.row - this._terminal.ydisp, false);
+    return true;
+  }
+}
diff --git a/src/addons/search/search.ts b/src/addons/search/search.ts
deleted file mode 100644 (file)
index 5a227a8..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * @license MIT
- */
-
-import { SearchHelper } from './SearchHelper';
-
-declare var exports: any;
-declare var module: any;
-declare var define: any;
-declare var require: any;
-declare var window: any;
-
-(function (addon) {
-  if ('Terminal' in window) {
-    /**
-     * Plain browser environment
-     */
-    addon(window.Terminal);
-  } else if (typeof exports === 'object' && typeof module === 'object') {
-    /**
-     * CommonJS environment
-     */
-    const xterm = '../../xterm';
-    module.exports = addon(require(xterm));
-  } else if (typeof define == 'function') {
-    /**
-     * Require.js is available
-     */
-    define(['../../xterm'], addon);
-  }
-})((Terminal: any) => {
-  /**
-   * 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.
-   * @return Whether a result was found.
-   */
-  Terminal.prototype.findNext = function(term: string): boolean {
-    if (!this._searchHelper) {
-      this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString);
-    }
-    return (<SearchHelper>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 Tne search term.
-   * @return Whether a result was found.
-   */
-  Terminal.prototype.findPrevious = function(term: string): boolean {
-    if (!this._searchHelper) {
-      this.searchHelper = new SearchHelper(this, Terminal.translateBufferLineToString);
-    }
-    return (<SearchHelper>this.searchHelper).findPrevious(term);
-  };
-});
diff --git a/src/addons/search/searchHelper.ts b/src/addons/search/searchHelper.ts
deleted file mode 100644 (file)
index f285144..0000000
+++ /dev/null
@@ -1,140 +0,0 @@
-/**
- * @license MIT
- */
-
-// import { ITerminal } from '../../Interfaces';
-// import { translateBufferLineToString } from '../../utils/BufferLine';
-
-interface ISearchResult {
-  term: string;
-  col: number;
-  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
-    // 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.
-   * @return Whether a result was found.
-   */
-  public findNext(term: string): boolean {
-    if (!term || term.length === 0) {
-      return false;
-    }
-
-    let result: ISearchResult;
-
-    let startRow = this._terminal.ydisp;
-    if (this._terminal.selectionManager.selectionEnd) {
-      // Start from the selection end if there is a selection
-      startRow = this._terminal.selectionManager.selectionEnd[1];
-    }
-
-    // Search from ydisp + 1 to end
-    for (let y = startRow + 1; y < this._terminal.ybase + this._terminal.rows; y++) {
-      result = this._findInLine(term, y);
-      if (result) {
-        break;
-      }
-    }
-
-    // Search from the top to the current ydisp
-    if (!result) {
-      for (let y = 0; y < startRow; y++) {
-        result = this._findInLine(term, y);
-        if (result) {
-          break;
-        }
-      }
-    }
-
-    // Set selection and scroll if a result was found
-    return this._selectResult(result);
-  }
-
-  /**
-   * 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.
-   * @return Whether a result was found.
-   */
-  public findPrevious(term: string): boolean {
-    if (!term || term.length === 0) {
-      return false;
-    }
-
-    let result: ISearchResult;
-
-    let startRow = this._terminal.ydisp;
-    if (this._terminal.selectionManager.selectionStart) {
-      // Start from the selection end if there is a selection
-      startRow = this._terminal.selectionManager.selectionStart[1];
-    }
-
-    // Search from ydisp + 1 to end
-    for (let y = startRow - 1; y >= 0; y--) {
-      result = this._findInLine(term, y);
-      if (result) {
-        break;
-      }
-    }
-
-    // Search from the top to the current ydisp
-    if (!result) {
-      for (let y = this._terminal.ybase + this._terminal.rows - 1; y > startRow; y--) {
-        result = this._findInLine(term, y);
-        if (result) {
-          break;
-        }
-      }
-    }
-
-    // Set selection and scroll if a result was found
-    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();
-    const lowerTerm = term.toLowerCase();
-    const searchIndex = lowerStringLine.indexOf(lowerTerm);
-    if (searchIndex >= 0) {
-      return {
-        term,
-        col: searchIndex,
-        row: y
-      };
-    }
-  }
-
-  /**
-   * 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;
-    }
-    this._terminal.selectionManager.setSelection(result.col, result.row, result.term.length);
-    this._terminal.scrollDisp(result.row - this._terminal.ydisp, false);
-    return true;
-  }
-}