mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
re #146841. allow single action view item to be disposed properly.
This commit is contained in:
parent
9fe0ba13ce
commit
eebc982128
|
@ -69,7 +69,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
|||
|
||||
// View Items
|
||||
viewItems: IActionViewItem[];
|
||||
private viewItemDisposables: DisposableStore;
|
||||
private viewItemDisposables: Map<IActionViewItem, IDisposable>;
|
||||
private previouslyFocusedItem?: number;
|
||||
protected focusedItem?: number;
|
||||
private focusTracker: DOM.IFocusTracker;
|
||||
|
@ -119,7 +119,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
|||
|
||||
this._actionIds = [];
|
||||
this.viewItems = [];
|
||||
this.viewItemDisposables = this._register(new DisposableStore());
|
||||
this.viewItemDisposables = new Map<IActionViewItem, IDisposable>();
|
||||
this.focusedItem = undefined;
|
||||
|
||||
this.domNode = document.createElement('div');
|
||||
|
@ -319,13 +319,6 @@ export class ActionBar extends Disposable implements IActionRunner {
|
|||
actionViewItemElement.className = 'action-item';
|
||||
actionViewItemElement.setAttribute('role', 'presentation');
|
||||
|
||||
// Prevent native context menu on actions
|
||||
if (!this.options.allowContextMenu) {
|
||||
this.viewItemDisposables.add(DOM.addDisposableListener(actionViewItemElement, DOM.EventType.CONTEXT_MENU, (e: DOM.EventLike) => {
|
||||
DOM.EventHelper.stop(e, true);
|
||||
}));
|
||||
}
|
||||
|
||||
let item: IActionViewItem | undefined;
|
||||
|
||||
if (this.options.actionViewItemProvider) {
|
||||
|
@ -336,6 +329,13 @@ export class ActionBar extends Disposable implements IActionRunner {
|
|||
item = new ActionViewItem(this.context, action, options);
|
||||
}
|
||||
|
||||
// Prevent native context menu on actions
|
||||
if (!this.options.allowContextMenu) {
|
||||
this.viewItemDisposables.set(item, DOM.addDisposableListener(actionViewItemElement, DOM.EventType.CONTEXT_MENU, (e: DOM.EventLike) => {
|
||||
DOM.EventHelper.stop(e, true);
|
||||
}));
|
||||
}
|
||||
|
||||
item.actionRunner = this._actionRunner;
|
||||
item.setActionContext(this.context);
|
||||
item.render(actionViewItemElement);
|
||||
|
@ -388,6 +388,8 @@ export class ActionBar extends Disposable implements IActionRunner {
|
|||
pull(index: number): void {
|
||||
if (index >= 0 && index < this.viewItems.length) {
|
||||
this.actionsList.removeChild(this.actionsList.childNodes[index]);
|
||||
this.viewItemDisposables.get(this.viewItems[index])?.dispose();
|
||||
this.viewItemDisposables.delete(this.viewItems[index]);
|
||||
dispose(this.viewItems.splice(index, 1));
|
||||
this._actionIds.splice(index, 1);
|
||||
this.refreshRole();
|
||||
|
@ -396,6 +398,7 @@ export class ActionBar extends Disposable implements IActionRunner {
|
|||
|
||||
clear(): void {
|
||||
dispose(this.viewItems);
|
||||
this.viewItemDisposables.forEach(d => d.dispose());
|
||||
this.viewItemDisposables.clear();
|
||||
this.viewItems = [];
|
||||
this._actionIds = [];
|
||||
|
|
Loading…
Reference in a new issue