improve menu positioning

This commit is contained in:
Salihu committed 2026-02-21 21:58:13 +01:00
1 parent 9b67d55f76
commit afb849ac98
2 files changed
+11 -8

No files matched your search

+9 -5
View File
@@ -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(
+2 -3
View File
@@ -49,10 +49,9 @@ const InlineMenu: React.FC<Props> = ({ 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
}
}