Merge pull request #5398 from Tyriar/tyriar/search-api-typing
Add proper typing for search results change event
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
|
import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm';
|
||||||
import type { SearchAddon as ISearchApi } from '@xterm/addon-search';
|
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';
|
import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||||
|
|
||||||
export interface ISearchOptions {
|
export interface ISearchOptions {
|
||||||
@@ -31,6 +31,11 @@ export interface ISearchPosition {
|
|||||||
startRow: number;
|
startRow: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ISearchResultChangeEvent {
|
||||||
|
resultIndex: number;
|
||||||
|
resultCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ISearchAddonOptions {
|
export interface ISearchAddonOptions {
|
||||||
highlightLimit: number;
|
highlightLimit: number;
|
||||||
}
|
}
|
||||||
@@ -86,8 +91,8 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA
|
|||||||
private _linesCacheTimeoutId = 0;
|
private _linesCacheTimeoutId = 0;
|
||||||
private _linesCacheDisposables = new MutableDisposable();
|
private _linesCacheDisposables = new MutableDisposable();
|
||||||
|
|
||||||
private readonly _onDidChangeResults = this._register(new Emitter<{ resultIndex: number, resultCount: number }>());
|
private readonly _onDidChangeResults = this._register(new Emitter<ISearchResultChangeEvent>());
|
||||||
public readonly onDidChangeResults = this._onDidChangeResults.event;
|
public get onDidChangeResults(): Event<ISearchResultChangeEvent> { return this._onDidChangeResults.event; }
|
||||||
|
|
||||||
constructor(options?: Partial<ISearchAddonOptions>) {
|
constructor(options?: Partial<ISearchAddonOptions>) {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ test.afterAll(async () => await ctx.page.close());
|
|||||||
test.describe('Search Tests', () => {
|
test.describe('Search Tests', () => {
|
||||||
|
|
||||||
test.beforeEach(async () => {
|
test.beforeEach(async () => {
|
||||||
|
await ctx.proxy.reset();
|
||||||
await ctx.page.evaluate(`
|
await ctx.page.evaluate(`
|
||||||
window.term.reset()
|
|
||||||
window.search?.dispose();
|
window.search?.dispose();
|
||||||
window.search = new SearchAddon();
|
window.search = new SearchAddon();
|
||||||
window.term.loadAddon(window.search);
|
window.term.loadAddon(window.search);
|
||||||
|
|||||||
+16
-2
@@ -75,6 +75,21 @@ declare module '@xterm/addon-search' {
|
|||||||
activeMatchColorOverviewRuler: string;
|
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.
|
* Options for the search addon.
|
||||||
*/
|
*/
|
||||||
@@ -139,8 +154,7 @@ declare module '@xterm/addon-search' {
|
|||||||
/**
|
/**
|
||||||
* When decorations are enabled, fires when
|
* When decorations are enabled, fires when
|
||||||
* the search results change.
|
* 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<ISearchResultChangeEvent>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user