From 76a8a8e3471d98a5289dbb4d061c1f6aceb9dee7 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 17 Sep 2025 08:52:38 -0700 Subject: [PATCH 1/2] 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 --- addons/addon-search/src/SearchAddon.ts | 31 +++++++++----------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/addons/addon-search/src/SearchAddon.ts b/addons/addon-search/src/SearchAddon.ts index 8395e437..72ca483c 100644 --- a/addons/addon-search/src/SearchAddon.ts +++ b/addons/addon-search/src/SearchAddon.ts @@ -4,28 +4,14 @@ */ import type { Terminal, IDisposable, ITerminalAddon, IDecoration } from '@xterm/xterm'; -import type { SearchAddon as ISearchApi } from '@xterm/addon-search'; +import type { SearchAddon as ISearchApi, ISearchOptions, ISearchDecorationOptions } from '@xterm/addon-search'; import { Emitter } from 'vs/base/common/event'; import { combinedDisposable, Disposable, dispose, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle'; -export interface ISearchOptions { - regex?: boolean; - wholeWord?: boolean; - caseSensitive?: boolean; - incremental?: boolean; - decorations?: ISearchDecorationOptions; +interface IInternalSearchOptions { noScroll?: boolean; } -interface ISearchDecorationOptions { - matchBackground?: string; - matchBorder?: string; - matchOverviewRuler: string; - activeMatchBackground?: string; - activeMatchBorder?: string; - activeMatchColorOverviewRuler: string; -} - export interface ISearchPosition { startCol: number; startRow: number; @@ -110,7 +96,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA this._highlightTimeout = setTimeout(() => { const term = this._cachedSearchTerm; this._cachedSearchTerm = undefined; - this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true, noScroll: true }); + // Pass noScroll as true for internal incremental update + this._findPreviousAndSelect(term!, this._lastSearchOptions, { noScroll: true }); + this._fireResults(this._lastSearchOptions); + this._cachedSearchTerm = term; }, 200); } } @@ -237,7 +226,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA return result; } - private _findNextAndSelect(term: string, searchOptions?: ISearchOptions): boolean { + private _findNextAndSelect(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean { if (!this._terminal || !term || term.length === 0) { this._terminal?.clearSelection(); this.clearDecorations(); @@ -302,7 +291,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA } // Set selection and scroll if a result was found - return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll); + return this._selectResult(result, searchOptions?.decorations, internalSearchOptions?.noScroll); } /** * 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 } } - private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions): boolean { + private _findPreviousAndSelect(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } @@ -428,7 +417,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon , ISearchA } // Set selection and scroll if a result was found - return this._selectResult(result, searchOptions?.decorations, searchOptions?.noScroll); + return this._selectResult(result, searchOptions?.decorations, internalSearchOptions?.noScroll); } /** From 6ac9f59ef452f327f575cea86a9a0b4fd11714b3 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 17 Sep 2025 09:16:20 -0700 Subject: [PATCH 2/2] Fix tests --- addons/addon-search/src/SearchAddon.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/addons/addon-search/src/SearchAddon.ts b/addons/addon-search/src/SearchAddon.ts index 3ea5d9ad..68449fa3 100644 --- a/addons/addon-search/src/SearchAddon.ts +++ b/addons/addon-search/src/SearchAddon.ts @@ -122,10 +122,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp this._highlightTimeout = setTimeout(() => { const term = this._cachedSearchTerm; this._cachedSearchTerm = undefined; - // Pass noScroll as true for internal incremental update - this._findPreviousAndSelect(term!, this._lastSearchOptions, { noScroll: true }); - this._fireResults(this._lastSearchOptions); - this._cachedSearchTerm = term; + this.findPrevious(term!, { ...this._lastSearchOptions, incremental: true }, { noScroll: true }); }, 200); } } @@ -152,7 +149,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp * @param searchOptions Search options. * @returns Whether a result was found. */ - public findNext(term: string, searchOptions?: ISearchOptions): boolean { + public findNext(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } @@ -164,7 +161,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp } } - const found = this._findNextAndSelect(term, searchOptions); + const found = this._findNextAndSelect(term, searchOptions, internalSearchOptions); this._fireResults(searchOptions); this._cachedSearchTerm = term; @@ -326,7 +323,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp * @param searchOptions Search options. * @returns Whether a result was found. */ - public findPrevious(term: string, searchOptions?: ISearchOptions): boolean { + public findPrevious(term: string, searchOptions?: ISearchOptions, internalSearchOptions?: IInternalSearchOptions): boolean { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } @@ -338,7 +335,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon, ISearchAp } } - const found = this._findPreviousAndSelect(term, searchOptions); + const found = this._findPreviousAndSelect(term, searchOptions, internalSearchOptions); this._fireResults(searchOptions); this._cachedSearchTerm = term;