Skip to content

Commit

Permalink
fix leaking event listeners (#207738)
Browse files Browse the repository at this point in the history
* fix leaking event listeners

* add mutabledisposable
  • Loading branch information
andreamah authored Mar 19, 2024
1 parent 2aa0f1c commit 6feba91
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class SearchView extends ViewPane {
this.instantiationService = this.instantiationService.createChild(
new ServiceCollection([IContextKeyService, this.contextKeyService]));

this.configurationService.onDidChangeConfiguration(e => {
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('search.sortOrder')) {
if (this.searchConfig.sortOrder === SearchSortOrder.Modified) {
// If changing away from modified, remove all fileStats
Expand All @@ -251,7 +251,7 @@ export class SearchView extends ViewPane {
} else if (e.affectsConfiguration('search.aiResults')) {
this.refreshHasAISetting();
}
});
}));

this.viewModel = this._register(this.searchViewModelWorkbenchService.searchModel);
this.queryBuilder = this.instantiationService.createInstance(QueryBuilder);
Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/search/browser/searchWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { NotebookEditorInput } from 'vs/workbench/contrib/notebook/common/notebo
import { GroupModelChangeKind } from 'vs/workbench/common/editor';
import { SearchFindInput } from 'vs/workbench/contrib/search/browser/searchFindInput';
import { getDefaultHoverDelegate } from 'vs/base/browser/ui/hover/hoverDelegateFactory';
import { IDisposable, MutableDisposable } from 'vs/base/common/lifecycle';

/** Specified in searchview.css */
const SingleLineInputHeight = 26;
Expand Down Expand Up @@ -171,6 +172,7 @@ export class SearchWidget extends Widget {
public contextLinesInput!: InputBox;

private _notebookFilters: NotebookFindFilters;
private _toggleReplaceButtonListener: MutableDisposable<IDisposable>;

constructor(
container: HTMLElement,
Expand Down Expand Up @@ -220,6 +222,7 @@ export class SearchWidget extends Widget {
}));

this._replaceHistoryDelayer = new Delayer<void>(500);
this._toggleReplaceButtonListener = this._register(new MutableDisposable<IDisposable>());

this.render(container, options);

Expand Down Expand Up @@ -380,8 +383,7 @@ export class SearchWidget extends Widget {
this.toggleReplaceButton.element.setAttribute('aria-expanded', 'false');
this.toggleReplaceButton.element.classList.add('toggle-replace-button');
this.toggleReplaceButton.icon = searchHideReplaceIcon;
// TODO@joao need to dispose this listener eventually
this.toggleReplaceButton.onDidClick(() => this.onToggleReplaceButton());
this._toggleReplaceButtonListener.value = this.toggleReplaceButton.onDidClick(() => this.onToggleReplaceButton());
}

private renderSearchInput(parent: HTMLElement, options: ISearchWidgetOptions): void {
Expand Down
12 changes: 2 additions & 10 deletions src/vs/workbench/services/search/common/searchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as arrays from 'vs/base/common/arrays';
import { DeferredPromise } from 'vs/base/common/async';
import { DeferredPromise, raceCancellationError } from 'vs/base/common/async';
import { CancellationToken } from 'vs/base/common/cancellation';
import { CancellationError } from 'vs/base/common/errors';
import { Disposable, IDisposable, toDisposable } from 'vs/base/common/lifecycle';
Expand Down Expand Up @@ -207,15 +207,7 @@ export class SearchService extends Disposable implements ISearchService {
};
})();

return new Promise((resolve, reject) => {
if (token) {
token.onCancellationRequested(() => {
reject(new CancellationError());
});
}

providerPromise.then(resolve, reject);
});
return token ? raceCancellationError<ISearchComplete>(providerPromise, token) : providerPromise;
}

private getSchemesInQuery(query: ISearchQuery): Set<string> {
Expand Down

0 comments on commit 6feba91

Please sign in to comment.