From 6e833e5d5d958642117eca457be7e18d61b799a5 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 17 Sep 2025 07:33:43 -0700 Subject: [PATCH] Add proper typing for search results change event - Export ISearchResultChangeEvent interface in addon-search - Use proper Event typing instead of inline object - Improve API consistency and type safety for consumers --- addons/addon-search/src/SearchAddon.ts | 11 ++++++++--- addons/addon-search/test/SearchAddon.test.ts | 2 +- addons/addon-search/typings/addon-search.d.ts | 18 ++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/addons/addon-search/src/SearchAddon.ts b/addons/addon-search/src/SearchAddon.ts index 8395e437..b65cfdd6 100644 --- a/addons/addon-search/src/SearchAddon.ts +++ b/addons/addon-search/src/SearchAddon.ts @@ -5,7 +5,7 @@ import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm'; import type { SearchAddon as ISearchApi } from '@xterm/addon-search'; -import { Emitter } from 'vs/base/common/event'; +import { Emitter, Event } from 'vs/base/common/event'; import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; export interface ISearchOptions { @@ -31,6 +31,11 @@ export interface ISearchPosition { startRow: number; } +export interface ISearchResultChangeEvent { + resultIndex: number; + resultCount: number; +} + export interface ISearchAddonOptions { highlightLimit: number; } @@ -86,8 +91,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA private _linesCacheTimeoutId = 0; private _linesCacheDisposables = new MutableDisposable(); - private readonly _onDidChangeResults = this._register(new Emitter<{ resultIndex: number, resultCount: number }>()); - public readonly onDidChangeResults = this._onDidChangeResults.event; + private readonly _onDidChangeResults = this._register(new Emitter()); + public get onDidChangeResults(): Event { return this._onDidChangeResults.event; } constructor(options?: Partial) { super(); diff --git a/addons/addon-search/test/SearchAddon.test.ts b/addons/addon-search/test/SearchAddon.test.ts index 232686b4..7b551e0c 100644 --- a/addons/addon-search/test/SearchAddon.test.ts +++ b/addons/addon-search/test/SearchAddon.test.ts @@ -19,8 +19,8 @@ test.afterAll(async () => await ctx.page.close()); test.describe('Search Tests', () => { test.beforeEach(async () => { + await ctx.proxy.reset(); await ctx.page.evaluate(` - window.term.reset() window.search?.dispose(); window.search = new SearchAddon(); window.term.loadAddon(window.search); diff --git a/addons/addon-search/typings/addon-search.d.ts b/addons/addon-search/typings/addon-search.d.ts index 282004a2..4c0df5a6 100644 --- a/addons/addon-search/typings/addon-search.d.ts +++ b/addons/addon-search/typings/addon-search.d.ts @@ -75,6 +75,21 @@ declare module '@xterm/addon-search' { activeMatchColorOverviewRuler: string; } + /** + * Event data fired when search results change. + */ + export interface ISearchResultChangeEvent { + /** + * The index of the currently active result, -1 when the threshold of matches is exceeded. + */ + resultIndex: number; + + /** + * The total number of search results found. + */ + resultCount: number; + } + /** * Options for the search addon. */ @@ -139,8 +154,7 @@ declare module '@xterm/addon-search' { /** * When decorations are enabled, fires when * the search results change. - * @returns -1 for resultIndex when the threshold of matches is exceeded. */ - readonly onDidChangeResults: IEvent<{ resultIndex: number, resultCount: number }>; + readonly onDidChangeResults: IEvent; } }