From cfde4d634f630b8cf09d95209afbfcebd58e45b0 Mon Sep 17 00:00:00 2001 From: tisilent Date: Sun, 1 Oct 2023 20:39:10 +0800 Subject: [PATCH 1/2] Check option changes --- addons/xterm-addon-search/src/SearchAddon.ts | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 959214c9..79cd010b 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -134,9 +134,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } + const isOptionsChanged = this._lastSearchOptions ? this._isOptionsChange(this._lastSearchOptions, searchOptions) : true; this._lastSearchOptions = searchOptions; if (searchOptions?.decorations) { - if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm) { + if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || isOptionsChanged) { this._highlightAllMatches(term, searchOptions); } } @@ -302,9 +303,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } + const isOptionsChanged = this._lastSearchOptions ? this._isOptionsChange(this._lastSearchOptions, searchOptions) : true; this._lastSearchOptions = searchOptions; if (searchOptions?.decorations) { - if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm) { + if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || isOptionsChanged) { this._highlightAllMatches(term, searchOptions); } } @@ -316,6 +318,22 @@ export class SearchAddon extends Disposable implements ITerminalAddon { return found; } + private _isOptionsChange(lastSearchOptions: ISearchOptions, searchOptions?: ISearchOptions): boolean { + if (!searchOptions) { + return false; + } + if (lastSearchOptions.caseSensitive !== searchOptions.caseSensitive) { + return true; + } + if (lastSearchOptions.regex !== searchOptions.regex) { + return true; + } + if (lastSearchOptions.wholeWord !== searchOptions.wholeWord) { + return true; + } + return false; + } + private _fireResults(searchOptions?: ISearchOptions): void { if (searchOptions?.decorations) { let resultIndex = -1; From 974b275f6e7051fce8b00c42771488e9386dd8d2 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 31 Oct 2023 06:41:16 -0700 Subject: [PATCH 2/2] is -> did --- addons/xterm-addon-search/src/SearchAddon.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/xterm-addon-search/src/SearchAddon.ts b/addons/xterm-addon-search/src/SearchAddon.ts index 79cd010b..c176a6f2 100644 --- a/addons/xterm-addon-search/src/SearchAddon.ts +++ b/addons/xterm-addon-search/src/SearchAddon.ts @@ -134,10 +134,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } - const isOptionsChanged = this._lastSearchOptions ? this._isOptionsChange(this._lastSearchOptions, searchOptions) : true; + const didOptionsChanged = this._lastSearchOptions ? this._didOptionsChange(this._lastSearchOptions, searchOptions) : true; this._lastSearchOptions = searchOptions; if (searchOptions?.decorations) { - if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || isOptionsChanged) { + if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || didOptionsChanged) { this._highlightAllMatches(term, searchOptions); } } @@ -303,10 +303,10 @@ export class SearchAddon extends Disposable implements ITerminalAddon { if (!this._terminal) { throw new Error('Cannot use addon until it has been loaded'); } - const isOptionsChanged = this._lastSearchOptions ? this._isOptionsChange(this._lastSearchOptions, searchOptions) : true; + const didOptionsChanged = this._lastSearchOptions ? this._didOptionsChange(this._lastSearchOptions, searchOptions) : true; this._lastSearchOptions = searchOptions; if (searchOptions?.decorations) { - if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || isOptionsChanged) { + if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || didOptionsChanged) { this._highlightAllMatches(term, searchOptions); } } @@ -318,7 +318,7 @@ export class SearchAddon extends Disposable implements ITerminalAddon { return found; } - private _isOptionsChange(lastSearchOptions: ISearchOptions, searchOptions?: ISearchOptions): boolean { + private _didOptionsChange(lastSearchOptions: ISearchOptions, searchOptions?: ISearchOptions): boolean { if (!searchOptions) { return false; }