Skip to content

Commit 6e833e5

Browse files
committed
Add proper typing for search results change event
- Export ISearchResultChangeEvent interface in addon-search - Use proper Event<T> typing instead of inline object - Improve API consistency and type safety for consumers
1 parent e969832 commit 6e833e5

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

addons/addon-search/src/SearchAddon.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

1111
export interface ISearchOptions {
@@ -31,6 +31,11 @@ export interface ISearchPosition {
3131
startRow: number;
3232
}
3333

34+
export interface ISearchResultChangeEvent {
35+
resultIndex: number;
36+
resultCount: number;
37+
}
38+
3439
export interface ISearchAddonOptions {
3540
highlightLimit: number;
3641
}
@@ -86,8 +91,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
8691
private _linesCacheTimeoutId = 0;
8792
private _linesCacheDisposables = new MutableDisposable();
8893

89-
private readonly _onDidChangeResults = this._register(new Emitter<{ resultIndex: number, resultCount: number }>());
90-
public readonly onDidChangeResults = this._onDidChangeResults.event;
94+
private readonly _onDidChangeResults = this._register(new Emitter<ISearchResultChangeEvent>());
95+
public get onDidChangeResults(): Event<ISearchResultChangeEvent> { return this._onDidChangeResults.event; }
9196

9297
constructor(options?: Partial<ISearchAddonOptions>) {
9398
super();

addons/addon-search/test/SearchAddon.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ test.afterAll(async () => await ctx.page.close());
1919
test.describe('Search Tests', () => {
2020

2121
test.beforeEach(async () => {
22+
await ctx.proxy.reset();
2223
await ctx.page.evaluate(`
23-
window.term.reset()
2424
window.search?.dispose();
2525
window.search = new SearchAddon();
2626
window.term.loadAddon(window.search);

addons/addon-search/typings/addon-search.d.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ declare module '@xterm/addon-search' {
7575
activeMatchColorOverviewRuler: string;
7676
}
7777

78+
/**
79+
* Event data fired when search results change.
80+
*/
81+
export interface ISearchResultChangeEvent {
82+
/**
83+
* The index of the currently active result, -1 when the threshold of matches is exceeded.
84+
*/
85+
resultIndex: number;
86+
87+
/**
88+
* The total number of search results found.
89+
*/
90+
resultCount: number;
91+
}
92+
7893
/**
7994
* Options for the search addon.
8095
*/
@@ -139,8 +154,7 @@ declare module '@xterm/addon-search' {
139154
/**
140155
* When decorations are enabled, fires when
141156
* the search results change.
142-
* @returns -1 for resultIndex when the threshold of matches is exceeded.
143157
*/
144-
readonly onDidChangeResults: IEvent<{ resultIndex: number, resultCount: number }>;
158+
readonly onDidChangeResults: IEvent<ISearchResultChangeEvent>;
145159
}
146160
}

0 commit comments

Comments
 (0)