Skip to content

Commit d4a4193

Browse files
authored
Fix wrong use of disposables (microsoft#211328)
fix microsoft#211096
1 parent 9c7f30b commit d4a4193

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

src/vs/editor/standalone/browser/standaloneServices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import { ConsoleLogger, ILogService } from 'vs/platform/log/common/log';
5555
import { IWorkspaceTrustManagementService, IWorkspaceTrustTransitionParticipant, IWorkspaceTrustUriInfo } from 'vs/platform/workspace/common/workspaceTrust';
5656
import { EditorOption } from 'vs/editor/common/config/editorOptions';
5757
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser';
58-
import { IContextMenuService, IContextViewDelegate, IContextViewService } from 'vs/platform/contextview/browser/contextView';
58+
import { IContextMenuService, IContextViewDelegate, IContextViewService, IOpenContextView } from 'vs/platform/contextview/browser/contextView';
5959
import { ContextViewService } from 'vs/platform/contextview/browser/contextViewService';
6060
import { LanguageService } from 'vs/editor/common/services/languageService';
6161
import { ContextMenuService } from 'vs/platform/contextview/browser/contextMenuService';
@@ -989,7 +989,7 @@ class StandaloneContextViewService extends ContextViewService {
989989
super(layoutService);
990990
}
991991

992-
override showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IDisposable {
992+
override showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IOpenContextView {
993993
if (!container) {
994994
const codeEditor = this._codeEditorService.getFocusedCodeEditor() || this._codeEditorService.getActiveCodeEditor();
995995
if (codeEditor) {

src/vs/platform/contextview/browser/contextView.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface IContextViewService extends IContextViewProvider {
1919

2020
readonly _serviceBrand: undefined;
2121

22-
showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IDisposable;
22+
showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IOpenContextView;
2323
hideContextView(data?: any): void;
2424
getContextViewElement(): HTMLElement;
2525
layout(): void;
@@ -48,6 +48,10 @@ export interface IContextViewDelegate {
4848
layer?: number; // Default: 0
4949
}
5050

51+
export interface IOpenContextView {
52+
close: () => void;
53+
}
54+
5155
export const IContextMenuService = createDecorator<IContextMenuService>('contextMenuService');
5256

5357
export interface IContextMenuService {

src/vs/platform/contextview/browser/contextViewService.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ContextView, ContextViewDOMPosition, IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
7-
import { Disposable, IDisposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
7+
import { Disposable } from 'vs/base/common/lifecycle';
88
import { ILayoutService } from 'vs/platform/layout/browser/layoutService';
9-
import { IContextViewDelegate, IContextViewService } from './contextView';
9+
import { IContextViewDelegate, IContextViewService, IOpenContextView } from './contextView';
1010
import { getWindow } from 'vs/base/browser/dom';
1111

12-
1312
export class ContextViewHandler extends Disposable implements IContextViewProvider {
1413

15-
private readonly currentViewDisposable = this._register(new MutableDisposable<IDisposable>());
14+
private openContextView: IOpenContextView | undefined;
1615
protected readonly contextView = this._register(new ContextView(this.layoutService.mainContainer, ContextViewDOMPosition.ABSOLUTE));
1716

1817
constructor(
@@ -26,7 +25,7 @@ export class ContextViewHandler extends Disposable implements IContextViewProvid
2625

2726
// ContextView
2827

29-
showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IDisposable {
28+
showContextView(delegate: IContextViewDelegate, container?: HTMLElement, shadowRoot?: boolean): IOpenContextView {
3029
let domPosition: ContextViewDOMPosition;
3130
if (container) {
3231
if (container === this.layoutService.getContainer(getWindow(container))) {
@@ -44,14 +43,16 @@ export class ContextViewHandler extends Disposable implements IContextViewProvid
4443

4544
this.contextView.show(delegate);
4645

47-
const disposable = toDisposable(() => {
48-
if (this.currentViewDisposable === disposable) {
49-
this.hideContextView();
46+
const openContextView: IOpenContextView = {
47+
close: () => {
48+
if (this.openContextView === openContextView) {
49+
this.hideContextView();
50+
}
5051
}
51-
});
52+
};
5253

53-
this.currentViewDisposable.value = disposable;
54-
return disposable;
54+
this.openContextView = openContextView;
55+
return openContextView;
5556
}
5657

5758
layout(): void {
@@ -60,6 +61,7 @@ export class ContextViewHandler extends Disposable implements IContextViewProvid
6061

6162
hideContextView(data?: any): void {
6263
this.contextView.hide(data);
64+
this.openContextView = undefined;
6365
}
6466
}
6567

src/vs/workbench/contrib/scm/browser/scmViewPane.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { ResourceLabels, IResourceLabel, IFileLabelOptions } from 'vs/workbench/
1616
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
1717
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
1818
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
19-
import { IContextViewService, IContextMenuService } from 'vs/platform/contextview/browser/contextView';
19+
import { IContextViewService, IContextMenuService, IOpenContextView } from 'vs/platform/contextview/browser/contextView';
2020
import { IContextKeyService, IContextKey, ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey';
2121
import { ICommandService } from 'vs/platform/commands/common/commands';
2222
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
@@ -2286,7 +2286,7 @@ class SCMInputWidget {
22862286
private readonly repositoryDisposables = new DisposableStore();
22872287

22882288
private validation: IInputValidation | undefined;
2289-
private validationDisposable: IDisposable = Disposable.None;
2289+
private validationContextView: IOpenContextView | undefined;
22902290
private validationHasFocus: boolean = false;
22912291
private _validationTimer: any;
22922292

@@ -2652,7 +2652,7 @@ class SCMInputWidget {
26522652

26532653
const disposables = new DisposableStore();
26542654

2655-
this.validationDisposable = this.contextViewService.showContextView({
2655+
this.validationContextView = this.contextViewService.showContextView({
26562656
getAnchor: () => this.element,
26572657
render: container => {
26582658
this.element.style.borderBottomLeftRadius = '0';
@@ -2733,7 +2733,8 @@ class SCMInputWidget {
27332733
}
27342734

27352735
clearValidation(): void {
2736-
this.validationDisposable.dispose();
2736+
this.validationContextView?.close();
2737+
this.validationContextView = undefined;
27372738
this.validationHasFocus = false;
27382739
}
27392740

0 commit comments

Comments
 (0)