From 492532aa60f36c0a40b8557a946275842bf6f26e Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Thu, 24 Nov 2022 22:19:34 +0800 Subject: [PATCH] fix:optimize contextmenu position --- src/editor/core/contextmenu/ContextMenu.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/editor/core/contextmenu/ContextMenu.ts b/src/editor/core/contextmenu/ContextMenu.ts index 961fbb8..c40283c 100644 --- a/src/editor/core/contextmenu/ContextMenu.ts +++ b/src/editor/core/contextmenu/ContextMenu.ts @@ -218,7 +218,13 @@ export class ContextMenu { } contextMenuContainer.append(contextMenuContent) contextMenuContainer.style.display = 'block' - contextMenuContainer.style.left = `${left}px` + const innerWidth = window.innerWidth + const contextMenuWidth = contextMenuContainer.getBoundingClientRect().width + // 右侧空间不足时,以菜单右上角作为起始点 + const adjustLeft = left + contextMenuWidth > innerWidth + ? left - contextMenuWidth + : left + contextMenuContainer.style.left = `${adjustLeft}px` contextMenuContainer.style.top = `${top}px` this.contextMenuContainerList.push(contextMenuContainer) return contextMenuContainer