Merge pull request #4831 from tisilent/fix-search-options-change

Check option changes
This commit is contained in:
Daniel Imms
2023-10-31 06:49:50 -07:00
committed by GitHub
+20 -2
View File
@@ -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 didOptionsChanged = this._lastSearchOptions ? this._didOptionsChange(this._lastSearchOptions, searchOptions) : true;
this._lastSearchOptions = searchOptions;
if (searchOptions?.decorations) {
if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm) {
if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || didOptionsChanged) {
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 didOptionsChanged = this._lastSearchOptions ? this._didOptionsChange(this._lastSearchOptions, searchOptions) : true;
this._lastSearchOptions = searchOptions;
if (searchOptions?.decorations) {
if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm) {
if (this._cachedSearchTerm === undefined || term !== this._cachedSearchTerm || didOptionsChanged) {
this._highlightAllMatches(term, searchOptions);
}
}
@@ -316,6 +318,22 @@ export class SearchAddon extends Disposable implements ITerminalAddon {
return found;
}
private _didOptionsChange(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;