Skip to content

Commit

Permalink
cleanup submenu container when disposed
Browse files Browse the repository at this point in the history
fixes #52917
  • Loading branch information
sbatten committed Jul 5, 2018
1 parent 20d26aa commit b4d512a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/vs/base/browser/ui/menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ResolvedKeybinding, KeyCode } from 'vs/base/common/keyCodes';
import { Event } from 'vs/base/common/event';
import { addClass, EventType, EventHelper, EventLike } from 'vs/base/browser/dom';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { $ } from 'vs/base/browser/builder';
import { $, Builder } from 'vs/base/browser/builder';

export interface IMenuOptions {
context?: any;
Expand Down Expand Up @@ -152,6 +152,7 @@ class MenuActionItem extends ActionItem {

class SubmenuActionItem extends MenuActionItem {
private mysubmenu: Menu;
private submenuContainer: Builder;
private mouseOver: boolean;

constructor(
Expand Down Expand Up @@ -224,37 +225,43 @@ class SubmenuActionItem extends MenuActionItem {
if (this.parentData.submenu && (force || (this.parentData.submenu !== this.mysubmenu))) {
this.parentData.submenu.dispose();
this.parentData.submenu = null;

this.submenuContainer.dispose();
this.submenuContainer = null;
}
}

private createSubmenu() {
if (!this.parentData.submenu) {
const submenuContainer = $(this.builder).div({ class: 'monaco-submenu menubar-menu-items-holder context-view' });
this.submenuContainer = $(this.builder).div({ class: 'monaco-submenu menubar-menu-items-holder context-view' });

$(submenuContainer).style({
$(this.submenuContainer).style({
'left': `${$(this.builder).getClientArea().width}px`
});

$(submenuContainer).on(EventType.KEY_UP, (e) => {
$(this.submenuContainer).on(EventType.KEY_UP, (e) => {
let event = new StandardKeyboardEvent(e as KeyboardEvent);
if (event.equals(KeyCode.LeftArrow)) {
EventHelper.stop(e, true);

this.parentData.parent.focus();
this.parentData.submenu.dispose();
this.parentData.submenu = null;

this.submenuContainer.dispose();
this.submenuContainer = null;
}
});

$(submenuContainer).on(EventType.KEY_DOWN, (e) => {
$(this.submenuContainer).on(EventType.KEY_DOWN, (e) => {
let event = new StandardKeyboardEvent(e as KeyboardEvent);
if (event.equals(KeyCode.LeftArrow)) {
EventHelper.stop(e, true);
}
});


this.parentData.submenu = new Menu(submenuContainer.getHTMLElement(), this.submenuActions, this.submenuOptions);
this.parentData.submenu = new Menu(this.submenuContainer.getHTMLElement(), this.submenuActions, this.submenuOptions);
this.parentData.submenu.focus();

this.mysubmenu = this.parentData.submenu;
Expand All @@ -268,5 +275,10 @@ class SubmenuActionItem extends MenuActionItem {
this.mysubmenu.dispose();
this.mysubmenu = null;
}

if (this.submenuContainer) {
this.submenuContainer.dispose();
this.submenuContainer = null;
}
}
}

0 comments on commit b4d512a

Please sign in to comment.