Skip to content

Commit

Permalink
chore: integrate changes required by Theia
Browse files Browse the repository at this point in the history
Adapts the "menubar" to support documents different than the global
one. This is required when rendering a menubar in a different window
which has its own document.

Adapts the "menu" to remove the check for empty menus. Menus in Theia
are dynamic and therefore by default empty until they are shown. This
check therefore prevents opening all menus in Theia.
  • Loading branch information
sdirix committed Oct 4, 2024
1 parent 5500353 commit adf3a88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/widgets/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ export class Menu extends Widget {
this.node.addEventListener('mouseenter', this);
this.node.addEventListener('mouseleave', this);
this.node.addEventListener('contextmenu', this);
document.addEventListener('mousedown', this, true);
this.node.ownerDocument.addEventListener('mousedown', this, true);
}

/**
Expand All @@ -533,7 +533,7 @@ export class Menu extends Widget {
this.node.removeEventListener('mouseenter', this);
this.node.removeEventListener('mouseleave', this);
this.node.removeEventListener('contextmenu', this);
document.removeEventListener('mousedown', this, true);
this.node.ownerDocument.removeEventListener('mousedown', this, true);
}

/**
Expand Down Expand Up @@ -1446,8 +1446,8 @@ namespace Private {
* Create the DOM node for a menu.
*/
export function createNode(): HTMLDivElement {
let node = document.createElement('div');
let content = document.createElement('ul');
let node = this.node.ownerDocument.createElement('div');
let content = this.node.ownerDocument.createElement('ul');
content.className = 'lm-Menu-content';
node.appendChild(content);
content.setAttribute('role', 'menu');
Expand Down Expand Up @@ -1545,8 +1545,8 @@ namespace Private {
return {
pageXOffset: window.pageXOffset,
pageYOffset: window.pageYOffset,
clientWidth: document.documentElement.clientWidth,
clientHeight: document.documentElement.clientHeight
clientWidth: this.node.ownerDocument.documentElement.clientWidth,
clientHeight: this.node.ownerDocument.documentElement.clientHeight
};
}

Expand Down Expand Up @@ -1636,7 +1636,7 @@ namespace Private {
style.maxHeight = `${maxHeight}px`;

// Attach the menu to the document.
Widget.attach(submenu, document.body);
Widget.attach(submenu, this.node.ownerDocument.body);

// Measure the size of the menu.
let { width, height } = node.getBoundingClientRect();
Expand Down
5 changes: 0 additions & 5 deletions packages/widgets/src/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,6 @@ export class MenuBar extends Widget {
value = -1;
}

// An empty menu cannot be active
if (value > -1 && this._menus[value].items.length === 0) {
value = -1;
}

// Bail early if the index will not change.
if (this._activeIndex === value) {
return;
Expand Down

0 comments on commit adf3a88

Please sign in to comment.