Rick Strahl
Rick Strahl

Reputation: 17651

Ace Editor: Get Mouse Position from a Cursor Position

I need to be able to get a physical mouse position (in pixels as an offset from the viewport) for the active cursor in ACE Editor. Ace provides all of it's positioning info via colum and row positions (ie. GetCursorPosition()), but i can't find a way to get a mouse position from that location.

The use case is to explicitly pop up an external (non-html) context menu in a host application, at the cursor position rather than at the mouse position when using keyboard only navigation of the document.

I already track the mouse position via mouse events, so I can pop up at the mouse cursor. However, I've been unable to handle the scenario when the mouse pointer is elsewhere because the user is navigating the document with the keyboard. I then need to pop up the custom menu for spell checking and general context sensitive tasks.

Without an absolute mouse position however, the menu can't be popped up in the correct place as I can't co-relate ACE's row/column position to a physical mouse position.

Any ideas how to get a mouse position from the cursor position?

Upvotes: 0

Views: 439

Answers (1)

a user
a user

Reputation: 24104

use editor.renderer.textToScreenCoordinates(row, column) which returns an object in the form {pageX: number, pageY: number} https://ajaxorg.github.io/ace-api-docs/classes/Ace.VirtualRenderer.html#textToScreenCoordinates

Upvotes: 1

Related Questions