Skip to content

Commit 76a8a8e

Browse files
committed
Refactor search addon types and internal handling
- Import search types from addon-search package - Add IInternalSearchOptions interface for noScroll param - Update _updateMatches to use internal search methods - Pass internal options through search method chain
1 parent e969832 commit 76a8a8e

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

addons/addon-search/src/SearchAddon.ts

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,14 @@
44
*/
55

66
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
7-
import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
7+
import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search';
88
import { Emitter } from 'vs/base/common/event';
99
import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
1010

11-
export interface ISearchOptions {
12-
regex?: boolean;
13-
wholeWord?: boolean;
14-
caseSensitive?: boolean;
15-
incremental?: boolean;
16-
decorations?: ISearchDecorationOptions;
11+
interface IInternalSearchOptions {
1712
noScroll?: boolean;
1813
}
1914

20-
interface ISearchDecorationOptions {
21-
matchBackground?: string;
22-
matchBorder?: string;
23-
matchOverviewRuler: string;
24-
activeMatchBackground?: string;
25-
activeMatchBorder?: string;
26-
activeMatchColorOverviewRuler: string;
27-
}
28-
2915
export interface ISearchPosition {
3016
startCol: number;
3117
startRow: number;
@@ -110,7 +96,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
11096
this._highlightTimeout = setTimeout(() => {
11197
const term = this._cachedSearchTerm;
11298
this._cachedSearchTerm = undefined;
113-
this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true, noScroll: true });
99+
// Pass noScroll as true for internal incremental update
100+
this._findPreviousAndSelect(term!, this._lastSearchOptions, { noScroll: true });
101+
this._fireResults(this._lastSearchOptions);
102+
this._cachedSearchTerm = term;
114103
}, 200);
115104
}
116105
}
@@ -237,7 +226,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
237226
return result;
238227
}
239228

240-
private _findNextAndSelect(term: string, searchOptions?: ISearchOptions): boolean {
229+
private _findNextAndSelect(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean {
241230
if (!this._terminal || !term || term.length === 0) {
242231
this._terminal?.clearSelection();
243232
this.clearDecorations();
@@ -302,7 +291,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
302291
}
303292

304293
// Set selection and scroll if a result was found
305-
return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll);
294+
return this._selectResult(result, searchOptions?.decorations, internalSearchOptions?.noScroll);
306295
}
307296
/**
308297
* Find the previous instance of the term, then scroll to and select it. If it
@@ -363,7 +352,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
363352
}
364353
}
365354

366-
private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions): boolean {
355+
private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean {
367356
if (!this._terminal) {
368357
throw new Error('Cannot use addon until it has been loaded');
369358
}
@@ -428,7 +417,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
428417
}
429418

430419
// Set selection and scroll if a result was found
431-
return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll);
420+
return this._selectResult(result, searchOptions?.decorations, internalSearchOptions?.noScroll);
432421
}
433422

434423
/**

0 commit comments

Comments
 (0)