Question

I want to be able to find where the user clicked in the document to bring up the right click context menu. Basically i want to be able to see the exact position of the cursor under the click.

I am handling the right click menu item with the following code, however the eventArgs im using dont have any detail on what the menu was triggered on. Ideally i want to be able to pinpoint how far through the code the user clicked.

private void MenuItemCallback(object sender, EventArgs e)
{
    DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE ;
    TextDocument activeDoc = dte.ActiveDocument.Object() as TextDocument;

    var text = activeDoc.CreateEditPoint(activeDoc.StartPoint).GetText(activeDoc.EndPoint);
}
Was it helpful?

Solution

ActivePoint can be used to deal with most cases:

activeDoc.Selection.ActivePoint

This will get the active point clicked, but it may give different results if the area clicked is already part of a selection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top