From afb849ac98d7edee5df4fdee8667b637a8fed115 Mon Sep 17 00:00:00 2001 From: Salihu Date: Sat, 21 Feb 2026 21:58:13 +0100 Subject: [PATCH] improve menu positioning --- app/editor/components/FloatingToolbar.tsx | 14 +++++++++----- app/editor/components/InlineMenu.tsx | 5 ++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/editor/components/FloatingToolbar.tsx b/app/editor/components/FloatingToolbar.tsx index 5979bed515..85017d996a 100644 --- a/app/editor/components/FloatingToolbar.tsx +++ b/app/editor/components/FloatingToolbar.tsx @@ -122,6 +122,7 @@ export function usePosition({ selection instanceof ColumnSelection && selection.isColSelection(); const isRowSelection = selection instanceof RowSelection && selection.isRowSelection(); + let colWidth = 0; if (isTableSelected(view.state)) { const rect = selectedRect(view.state); @@ -138,6 +139,7 @@ export function usePosition({ ); if (element instanceof HTMLElement) { const bounds = element.getBoundingClientRect(); + colWidth = bounds.width; selectionBounds.top = bounds.top - 16; selectionBounds.left = bounds.left; selectionBounds.right = bounds.right; @@ -200,11 +202,13 @@ export function usePosition({ ), Math.max( Math.max(offsetParent.x, margin), - align === "center" - ? centerOfSelection - menuWidth / 2 - : align === "start" - ? selectionBounds.left - : selectionBounds.right + isColSelection && colWidth < 300 + ? selectionBounds.right + margin + : align === "center" + ? centerOfSelection - menuWidth / 2 + : align === "start" + ? selectionBounds.left + : selectionBounds.right ) ); const top = Math.max( diff --git a/app/editor/components/InlineMenu.tsx b/app/editor/components/InlineMenu.tsx index 664c81fd23..60e2ce4fe2 100644 --- a/app/editor/components/InlineMenu.tsx +++ b/app/editor/components/InlineMenu.tsx @@ -49,10 +49,9 @@ const InlineMenu: React.FC = ({ items, containerRef }) => { let left = position.left; if (menuRef.current && menuRect) { - const spaceOnRight = - viewportWidth - menuRef.current?.offsetWidth - position.left; + const spaceOnRight = viewportWidth - left; if (spaceOnRight < menuRect.right) { - left = position.left - spaceOnRight; + left = left - spaceOnRight; // double the space on the right } }