Context Menu: Change positioning algorithm for y-axis

This commit is contained in:
somebody
2023-07-21 13:48:23 -05:00
parent 1c4157a41b
commit b8671cce09

View File

@@ -5818,8 +5818,21 @@ function position_context_menu(contextMenu, x, y) {
right: x + width, right: x + width,
}; };
// Slide over if running against the window bounds.
if (farMenuBounds.right > bounds.right) x -= farMenuBounds.right - bounds.right; if (farMenuBounds.right > bounds.right) x -= farMenuBounds.right - bounds.right;
if (farMenuBounds.bottom > bounds.bottom) y -= farMenuBounds.bottom - bounds.bottom;
if (farMenuBounds.bottom > bounds.bottom) {
// We've hit the bottom.
// The old algorithm pushed the menu against the wall, similar to what's
// done on the x-axis:
// y -= farMenuBounds.bottom - bounds.bottom;
// But now, we make the box change its emission direction from the cursor:
y -= (height + 5);
// The main advantage of this approach is that the cursor is never directly
// placed above a context menu item immediately after activating the context
// menu. (Thus the 5px offset also added)
}
contextMenu.style.left = `${x}px`; contextMenu.style.left = `${x}px`;
contextMenu.style.top = `${y}px`; contextMenu.style.top = `${y}px`;