From c7a1f4924a63e929f11c673864799a72a830609d Mon Sep 17 00:00:00 2001 From: Jonah Iden Date: Thu, 7 Nov 2024 16:53:31 +0100 Subject: [PATCH] fix upper most context menu item sometimes not clickable in electron (#14401) * fix upper most context menu item sometimes not clickable in electron Signed-off-by: Jonah Iden * retrieve top panel height instead of hardcoding it Signed-off-by: Jonah Iden --------- Signed-off-by: Jonah Iden --- .../menu/electron-context-menu-renderer.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts b/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts index 7633930144c03..0c6f4b691a051 100644 --- a/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts +++ b/packages/core/src/electron-browser/menu/electron-context-menu-renderer.ts @@ -23,7 +23,7 @@ import { import { ElectronMainMenuFactory } from './electron-main-menu-factory'; import { ContextMenuContext } from '../../browser/menu/context-menu-context'; import { MenuPath, MenuContribution, MenuModelRegistry } from '../../common'; -import { BrowserContextMenuRenderer } from '../../browser/menu/browser-context-menu-renderer'; +import { BrowserContextMenuAccess, BrowserContextMenuRenderer } from '../../browser/menu/browser-context-menu-renderer'; export class ElectronContextMenuAccess extends ContextMenuAccess { constructor(readonly menuHandle: Promise) { @@ -115,7 +115,15 @@ export class ElectronContextMenuRenderer extends BrowserContextMenuRenderer { this.context.resetAltPressed(); return new ElectronContextMenuAccess(menuHandle); } else { - return super.doRender(options); + const menuAccess = super.doRender(options); + const node = (menuAccess as BrowserContextMenuAccess).menu.node; + const topPanelHeight = document.getElementById('theia-top-panel')?.clientHeight ?? 0; + // ensure the context menu is not displayed outside of the main area + if (node.style.top && parseInt(node.style.top.substring(0, node.style.top.length - 2)) < topPanelHeight) { + node.style.top = `${topPanelHeight}px`; + node.style.maxHeight = `calc(${node.style.maxHeight} - ${topPanelHeight}px)`; + } + return menuAccess; } }