From b9d10f1453e2c4e3bc0da2755a3e53253e3735e6 Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 23 Mar 2022 13:54:01 -0400 Subject: [PATCH 1/2] use correct start col/row --- addons/xterm-addon-search/src/SearchAddon.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 3dd2992dac..0e0fcef13e 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -139,7 +139,12 @@ export class SearchAddon implements ITerminalAddon { let result = this._find(term, 0, 0, searchOptions); while (result && !this._searchResults.get(`${result.row}-${result.col}`)) { this._searchResults.set(`${result.row}-${result.col}`, result); - result = this._find(term, result.row, result.col + 1, searchOptions); + result = this._find( + term, + result.col + result.term.length >= this._terminal.cols ? result.row + 1 : result.row, + result.col + result.term.length >= this._terminal.cols ? 0 : result.col + 1, + searchOptions + ); } this._searchResults.forEach(result => { const resultDecoration = this._createResultDecoration(result, searchOptions.decorations!); @@ -157,15 +162,13 @@ export class SearchAddon implements ITerminalAddon { } } - private _find(term: string, startRow?: number, startCol?: number, searchOptions?: ISearchOptions): ISearchResult | undefined { + private _find(term: string, startRow: number, startCol: number, searchOptions?: ISearchOptions): ISearchResult | undefined { if (!this._terminal || !term || term.length === 0) { this._terminal?.clearSelection(); this.clearDecorations(); return undefined; } let result: ISearchResult | undefined = undefined; - startCol = startCol || 0; - startRow = startRow ?? 0; this._initLinesCache(); From 3a0f64545ecc4dfeaa4c48f8eba23df65f6f434c Mon Sep 17 00:00:00 2001 From: meganrogge Date: Wed, 23 Mar 2022 14:01:56 -0400 Subject: [PATCH 2/2] throw for invalid row or col --- addons/xterm-addon-search/src/SearchAddon.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 0e0fcef13e..0f677072cf 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -168,6 +168,10 @@ export class SearchAddon implements ITerminalAddon { this.clearDecorations(); return undefined; } + if (startRow > this._terminal.rows || startCol > this._terminal.cols) { + throw new Error(`Invalid row: ${startRow} or col: ${startCol} to search in terminal with ${this._terminal.rows} rows and ${this._terminal.cols} cols`); + } + let result: ISearchResult | undefined = undefined; this._initLinesCache();