MCPcopy
hub / github.com/xtermjs/xterm.js / find

Method find

addons/addon-search/src/SearchEngine.ts:58–88  ·  view source on GitHub ↗

* Find the first occurrence of a term starting from a specific position. * @param term The search term. * @param startRow The row to start searching from. * @param startCol The column to start searching from. * @param searchOptions Search options. * @returns The search result if found

(term: string, startRow: number, startCol: number, searchOptions?: ISearchOptions)

Source from the content-addressed store, hash-verified

56 * @returns The search result if found, undefined otherwise.
57 */
58 public find(term: string, startRow: number, startCol: number, searchOptions?: ISearchOptions): ISearchResult | undefined {
59 if (!term || term.length === 0) {
60 this._terminal.clearSelection();
61 return undefined;
62 }
63 if (startCol > this._terminal.cols) {
64 throw new Error(`Invalid col: ${startCol} to search in terminal of ${this._terminal.cols} cols`);
65 }
66
67 this._lineCache.initLinesCache();
68
69 const searchPosition: ISearchPosition = {
70 startRow,
71 startCol
72 };
73
74 // Search startRow
75 let result = this._findInLine(term, searchPosition, searchOptions);
76 // Search from startRow + 1 to end
77 if (!result) {
78 for (let y = startRow + 1; y < this._terminal.buffer.active.baseY + this._terminal.rows; y++) {
79 searchPosition.startRow = y;
80 searchPosition.startCol = 0;
81 result = this._findInLine(term, searchPosition, searchOptions);
82 if (result) {
83 break;
84 }
85 }
86 }
87 return result;
88 }
89
90 /**
91 * Find the next occurrence of a term with wrapping and selection management.

Callers 6

getActiveDocumentFunction · 0.80
_highlightAllMatchesMethod · 0.80
esbuild.mjsFile · 0.80

Calls 3

_findInLineMethod · 0.95
initLinesCacheMethod · 0.80
clearSelectionMethod · 0.65

Tested by

no test coverage detected