Skip to content

Commit 687d827

Browse files
committed
Fix terminal find when wrapped
1 parent 4c0cf27 commit 687d827

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

addons/addon-search/src/SearchAddon.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
7272
private _cachedSearchTerm: string | undefined;
7373
private _highlightedLines: Set<number> = new Set();
7474
private _highlightDecorations: IHighlight[] = [];
75+
private _searchResultsWithHighlight: ISearchResult[] = [];
7576
private _selectedDecoration: MutableDisposable<IMultiHighlight> = this._register(new MutableDisposable());
7677
private _highlightLimit: number;
7778
private _lastSearchOptions: ISearchOptions | undefined;
@@ -118,6 +119,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
118119
this._selectedDecoration.clear();
119120
dispose(this._highlightDecorations);
120121
this._highlightDecorations = [];
122+
this._searchResultsWithHighlight = [];
121123
this._highlightedLines.clear();
122124
if (!retainCachedSearchTerm) {
123125
this._cachedSearchTerm = undefined;
@@ -167,23 +169,22 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
167169
// new search, clear out the old decorations
168170
this.clearDecorations(true);
169171

170-
const searchResultsWithHighlight: ISearchResult[] = [];
171172
let prevResult: ISearchResult | undefined = undefined;
172173
let result = this._find(term, 0, 0, searchOptions);
173174
while (result && (prevResult?.row !== result.row || prevResult?.col !== result.col)) {
174-
if (searchResultsWithHighlight.length >= this._highlightLimit) {
175+
if (this._searchResultsWithHighlight.length >= this._highlightLimit) {
175176
break;
176177
}
177178
prevResult = result;
178-
searchResultsWithHighlight.push(prevResult);
179+
this._searchResultsWithHighlight.push(prevResult);
179180
result = this._find(
180181
term,
181182
prevResult.col + prevResult.term.length >= this._terminal.cols ? prevResult.row + 1 : prevResult.row,
182183
prevResult.col + prevResult.term.length >= this._terminal.cols ? 0 : prevResult.col + 1,
183184
searchOptions
184185
);
185186
}
186-
for (const match of searchResultsWithHighlight) {
187+
for (const match of this._searchResultsWithHighlight) {
187188
const decorations = this._createResultDecorations(match, searchOptions.decorations!, false);
188189
if (decorations) {
189190
for (const decoration of decorations) {
@@ -350,15 +351,16 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
350351
let resultIndex = -1;
351352
if (this._selectedDecoration.value) {
352353
const selectedMatch = this._selectedDecoration.value.match;
353-
for (let i = 0; i < this._highlightDecorations.length; i++) {
354-
const match = this._highlightDecorations[i].match;
354+
// Problem: this.highlightDecorations.length was showing all lines of highlighted.
355+
for (let i = 0; i < this._searchResultsWithHighlight.length; i++) {
356+
const match = this._searchResultsWithHighlight[i];
355357
if (match.row === selectedMatch.row && match.col === selectedMatch.col && match.size === selectedMatch.size) {
356358
resultIndex = i;
357359
break;
358360
}
359361
}
360362
}
361-
this._onDidChangeResults.fire({ resultIndex, resultCount: this._highlightDecorations.length });
363+
this._onDidChangeResults.fire({ resultIndex, resultCount: this._searchResultsWithHighlight.length });
362364
}
363365
}
364366

0 commit comments

Comments
 (0)