How to overlay a control on a Visual Studio code surface

I am writing addin in Sql Server Management Studio using the Visual Studio Extensibilty API. I had some success overlaying a control on a text surface (I'm trying to emulate a CodeRush / Refactor action list similar to the intellisense command), however I can find its coordinate space based on the following property:

get
{
    var point = TextDocument.Selection.TopPoint;
    return new Cursor( point.DisplayColumn, point.Line );
}

This code allows me to convert cols / rows to pixels, however I cannot find a way to offset cols / rows when the text editor scrolls either vertically or horizontally. This will cause the list to disappear under the visible space of the screen.

What I'm looking for is a method to get the screen coordinates from the current col / row pair, so that I can place the list next to the cursor, regardless of the scroll position.

+3
source share
1 answer

The TextDocument.Selection property of the TextSelection type has the TextPane property - see here for more information. He does not explicitly say this, but TextPane is part of the visible screen. In addition, the StartPoint property for TextPane provides an “offset” of scrolled text.

Therefore, I was able to determine the position of the offset cursor by subtracting TextPane.StartPoint from the Start point of selection:

get
{
    var start = TextDocument.Selection.TextPane.StartPoint;
    var top = TextDocument.Selection.TopPoint;
    return new Cursor( 
        top.DisplayColumn - start.DisplayColumn + 1 , 
        top.Line - start.Line + 1 
    );
}
+1
source

Source: https://habr.com/ru/post/1720986/


All Articles