We're inserting text through a PasteDragDrop event, and we're having some issues with the position of the inserted text when the drop point is at an indent. The text we're editing is C# formatted, so typically a method body would be indented by one column (one tab) at the leftmost level, and more than that throughout the code blocks inside the method.
So, if I tab in three times on a new line, then drag and drop text at the caret position of that line (insert caret is shown in correct indentation position), the text is inserted before the last indentation. In other words, the inserted text is pasted one indentation level too far to the left, with one indentation level after. What I would expect is for the inserted text to be inserted after the indentations, so I don't know whether this is a bug or expected behavior we're seeing.
Here's the code used to insert (from codeEditor_PasteDragDrop method):
Point dropPoint = e.DragEventArgs.GetPosition(this);
IHitTestResult htResult = codeEditor.HitTest(dropPoint);
codeEditor.Document.InsertText(TextChangeTypes.Paste, htResult.Offset, "INSERTED TEXT");
If text is dropped within an existing line of code, indentation is not an issue and the text insert occurs at the correct location.
Is there any way to detect whether the insert caret is at an indentation level, and simply add to the htResult.Offset value? htResult.ViewLine.IndentAmount gives me the number of indent columns, but I can't quite figure out if and how I can make use of that value.
Hopefully someone can provide some insight into this little issue :-)
Espen