Inserting text at indentation position

SyntaxEditor for WPF Forum

Posted 7 years ago by Espen Øyan - Senior Software Engineer, Crosshairs Embedded
Version: 12.2.0570
Avatar

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

Comments (1)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Espen,

I'm not seeing that when I drag drop text within the editor itself.  But still I wonder if you aren't using the PasteDragDrop event properly.  We handle all the offset finding for you.  All you should be doing is setting the PasteDragDropEventArgs.Text property to your "INSERTED TEXT" value.  Then it will get inserted.  Don't bother with the GetPosition or InsertText method calls.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.