From 2cd14f8c8de0eb8764a458916ebcb2008c208be6 Mon Sep 17 00:00:00 2001 From: shuyaqian <717749594@qq.com> Date: Wed, 15 Dec 2021 16:48:08 +0800 Subject: [PATCH] fix default Anchor param of context menu Signed-off-by: shuyaqian 717749594@qq.com --- packages/core/src/browser/context-menu-renderer.ts | 7 +++++++ .../src/browser/debug-frontend-application-contribution.ts | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/src/browser/context-menu-renderer.ts b/packages/core/src/browser/context-menu-renderer.ts index 59c0a43365fc7..1371c15f42862 100644 --- a/packages/core/src/browser/context-menu-renderer.ts +++ b/packages/core/src/browser/context-menu-renderer.ts @@ -29,6 +29,13 @@ export function toAnchor(anchor: HTMLElement | Coordinate): Anchor { return anchor instanceof HTMLElement ? { x: anchor.offsetLeft, y: anchor.offsetTop } : anchor; } +export function isAnchor(arg: unknown): boolean { + if (arg && typeof arg === 'object' && 'x' in arg && 'y' in arg && Object.keys(arg).length === 2) { + return true; + } + return false; +} + export function coordinateFromAnchor(anchor: Anchor): Coordinate { const { x, y } = anchor instanceof MouseEvent ? { x: anchor.clientX, y: anchor.clientY } : anchor; return { x, y }; diff --git a/packages/debug/src/browser/debug-frontend-application-contribution.ts b/packages/debug/src/browser/debug-frontend-application-contribution.ts index d9b7757c8bb5e..6ebd7e3f47b46 100644 --- a/packages/debug/src/browser/debug-frontend-application-contribution.ts +++ b/packages/debug/src/browser/debug-frontend-application-contribution.ts @@ -14,7 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { AbstractViewContribution, ApplicationShell, KeybindingRegistry, Widget, CompositeTreeNode, LabelProvider, codicon } from '@theia/core/lib/browser'; +import { AbstractViewContribution, ApplicationShell, KeybindingRegistry, Widget, CompositeTreeNode, LabelProvider, codicon, isAnchor } from '@theia/core/lib/browser'; import { injectable, inject } from '@theia/core/shared/inversify'; import { ThemeService } from '@theia/core/lib/browser/theming'; import { MenuModelRegistry, CommandRegistry, MAIN_MENU_BAR, Command, Emitter, Mutable } from '@theia/core/lib/common'; @@ -640,10 +640,10 @@ export class DebugFrontendApplicationContribution extends AbstractViewContributi registerCommands(registry: CommandRegistry): void { super.registerCommands(registry); registry.registerCommand(DebugCommands.START, { - execute: (config?: DebugSessionOptions) => this.start(false, config) + execute: (config?: DebugSessionOptions) => this.start(false, isAnchor(config) ? undefined : config) }); registry.registerCommand(DebugCommands.START_NO_DEBUG, { - execute: (config?: DebugSessionOptions) => this.start(true, config) + execute: (config?: DebugSessionOptions) => this.start(true, isAnchor(config) ? undefined : config) }); registry.registerCommand(DebugCommands.STOP, { execute: () => this.manager.terminateSessions(),