Drag Drop to replace whole word

SyntaxEditor for WPF Forum

Posted 8 years ago by Andrew Hanlon
Version: 16.1.0633
Avatar

I have a document that contains 'identifiers' that I would like to replace if a drop occurs within them. For example I have the string:

LTRIM([foo])

after dropping a new identifer over '[foo]', I would like it to be replaced as in:

LTRIM([bar])

I have the drag and drop working to the point where my new identifier is being placed into the text, but I cannot seem to find where / when / how to examine and change the drop's TextPosition, which would also alow me to delete the original identifier and drop the new text into its staring point.

Ideally I would also like to select the whole identifier when the new identifier is dragged over top (before dropping).

What is the best way to accomplish this type of requirement?

 

Thanks.

[Modified 8 years ago]

Comments (6)

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

Hi Andrew,I believe the PasteDragDrop event files right before the text is replaced.  If it has an e.Action of DragDrop, you can update the view's selection to be over the range to replace (i.e. "foo").  When the event handler finishes, whatever is selected in the view is replaced.

You could probably get the hit test info with this sort of code in that event handler:

var pos = e.DragEventArgs.GetPosition(view.SyntaxEditor);
view.SyntaxEditor.HitTest(pos);


Actipro Software Support

Posted 8 years ago by Andrew Hanlon
Avatar

Thank you kindly, this got me headed in the right direction.

The PasteDragDrop event only seems to fire upon entry and the final drop. But the PreviewDragOver event in combination with the HitTest code you provided can be used to handle this situation.

Much appreciated.

Posted 8 years ago by Andrew Hanlon
Avatar

After getting the drag selection working nicely, I am now seeing that the selected text is still not being replaced, instead the text is still being placed at the 'drop caret'.

Is there a certain way that the selection needs to be set in order for that aspect to work?

Thanks.

Posted 8 years ago by Andrew Hanlon
Avatar

In the mean time, a work-around is to simply handle the replacement manually within the PasteDragDrop event, and set the Text argument to Null which prevents the insertion.

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

Yes, it looks like the selection does get set after the event fires and before the replace text change occurs.  What you are doing (doing the replace yourself and setting e.Text to null) is probably the best way to handle this.


Actipro Software Support

Posted 8 years ago by Andrew Hanlon
Avatar

Thanks. It's working well. 

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.