This repository was archived by the owner on Jan 30, 2026. It is now read-only.
Closed
Conversation
Co-authored-by: caiopizzol <caiopizzol@gmail.com>
|
Cursor Agent can help with this pull request. Just |
SD-546 Fix menu positioning near viewport edges
SummaryClamp menu position to viewport bounds so menu doesn't appear off-screen when trigger is near window edges Tasks
NotesProblem: When user types trigger near right/bottom edge of viewport, menu appears partially or fully off-screen Current code (src/index.tsx): const coords = e.view.coordsAtPos(from);
const bounds = new DOMRect(coords.left, coords.top, 0, 0);
setMenuPosition(bounds); // No boundary checkingSimple fix (don't over-engineer): const clampToViewport = (rect: DOMRect): DOMRect => {
const menuWidth = 250; // Approximate menu width
const menuHeight = 300; // Approximate menu height
const left = Math.min(
rect.left,
window.innerWidth - menuWidth - 10 // 10px padding
);
const top = Math.min(
rect.top,
window.innerHeight - menuHeight - 10
);
return new DOMRect(Math.max(left, 10), Math.max(top, 10), 0, 0);
};
// Usage
const coords = e.view.coordsAtPos(from);
const bounds = clampToViewport(new DOMRect(coords.left, coords.top, 0, 0));
setMenuPosition(bounds);Don't:
Do: Simple hard-coded approximations work fine for 99% of cases |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clamp menu position to viewport bounds to prevent it from appearing off-screen near window edges.
This is achieved by introducing a
clampToViewportfunction that uses hard-coded approximate menu dimensions and a fixed padding to adjust the menu's coordinates before setting its position, as per the issue's recommended simple fix.Linear Issue: SD-546