Skip to content

fix: align code selection menu with selection across editors#866

Open
ML-dev-crypto wants to merge 2 commits intoaccordproject:mainfrom
ML-dev-crypto:fix/code-selection-menu-position
Open

fix: align code selection menu with selection across editors#866
ML-dev-crypto wants to merge 2 commits intoaccordproject:mainfrom
ML-dev-crypto:fix/code-selection-menu-position

Conversation

@ML-dev-crypto
Copy link
Copy Markdown
Contributor

@ML-dev-crypto ML-dev-crypto commented Apr 1, 2026

Closes #865

Problem

The code selection menu was not correctly aligned with selected text, especially in the JSON editor. The horizontal position was constrained and did not reflect the actual selection position.

Changes

  • Replaced hardcoded X positioning with position.x
  • Used getBoundingClientRect() to convert editor-local coords to viewport coords in the fallback branch
  • Added early return if getDomNode() returns null
  • Improved multi-line selection handling

Testing

  • Verified menu alignment in TemplateMark editor
  • Verified menu alignment in JSON editor
  • Tested multi-line selections

Author Checklist

  • DCO sign-off provided (--signoff)
  • Commit messages follow AP conventional commits format
  • No documentation changes required
  • Merging to main from ML-dev-crypto:fix/code-selection-menu-position

- Replace hardcoded x=225 with position.x so menu follows selection horizontally
- Convert editor-relative coordinates to viewport coordinates by adding editorRect.left/top
- Use getEndPosition for Y so menu appears above last line of multi-line selections
- Use getStartPosition for X so menu anchors to selection start, not end cursor

Signed-off-by: ML-dev-crypto <ml.dev.crypto@example.com>
@ML-dev-crypto ML-dev-crypto requested a review from a team as a code owner April 1, 2026 19:43
Copilot AI review requested due to automatic review settings April 1, 2026 19:43
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 1, 2026

Deploy Preview for ap-template-playground ready!

Name Link
🔨 Latest commit c77844c
🔍 Latest deploy log https://app.netlify.com/projects/ap-template-playground/deploys/69ce8b232db89e0008a6fc3e
😎 Deploy Preview https://deploy-preview-866--ap-template-playground.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the CodeSelectionMenu placement so it follows the actual text selection position (X/Y) across Monaco-based editors, addressing misalignment that was especially visible in the JSON editor.

Changes:

  • Use position.x for the menu’s horizontal placement instead of a fixed X value.
  • Update useCodeSelection to compute menu coordinates using editor selection start/end visible positions and editor container offsets.
  • Improve multi-line selection handling by mixing start (X) and end (Y) selection coordinates.

Comment thread src/components/CodeSelectionMenu.tsx
Comment thread src/components/CodeSelectionMenu.tsx
When .editorwrapper container is not found, the fallback branch was using
editor-local coordinates directly as viewport coordinates, causing the menu
to appear near the page origin.
Fix: use editor.getDomNode().getBoundingClientRect() to get the editor's
viewport offset and add it to startPosition.left and endPosition.top before
clamping. Return early if getDomNode() returns null.

Signed-off-by: Ansh Rai <anshrai331@gmail.com>
@ML-dev-crypto ML-dev-crypto force-pushed the fix/code-selection-menu-position branch from 3b4a6a7 to c77844c Compare April 2, 2026 15:28
@ML-dev-crypto
Copy link
Copy Markdown
Contributor Author

Hi! @DianaLease any feedback

@ML-dev-crypto
Copy link
Copy Markdown
Contributor Author

Hi! @mttrbrts any feedback..????

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code selection menu always appears at fixed X position, ignoring actual selection location

2 participants