Detect Line Deletion by User

SyntaxEditor for Windows Forms Forum

Posted 11 months ago by John
Version: 22.1.1
Avatar

I need to be able to detect if line(s) are deleted (e.g. backspace, cut, Drag/Drop). Then, I need to know each of the "old" line numbers that are deleted in order to handle a certain event at each deleted "old" line number. 

I have a method in place already to detect text changes in the Editor that uses EditorSnapshotChangedEventArgs. 

[Modified 11 months ago]

Comments (5)

Posted 11 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi John,

The information you're looking for can be obtained by looking at the TextChange property on the EditorSnapshotChangedEventArgs that you are already handling (which is an instance of ITextChange).  The ITextChange.Operations property (which is a collection ITextChangeOperation instances) provides access to all of the changes that were made.

The ITextChange.Type property can help you determine the type of change (e.g. Delete).

You can use properties like ITextChangeOperation.StartPosition and ITextChangeOperation.LinesDeleted to know which line numbers were deleted.  For example, if StartPosition is line 20 and 2 lines were deleted, you know that lines 20 and 21 were deleted.

That should get you started in general. If you run into challenges with specific scenarios, please reach back out.


Actipro Software Support

Posted 11 months ago by John
Avatar

Ok can you help me figure out how to get the integer values of each deleted line number?

Using the code below, I want to be able to get access to each deleted line number and call the OnLineDeleted method for each deleted line

                if (e.TextChange.Type == TextChangeTypes.Delete)
                {
                    foreach (ITextChangeOperation operation in e.TextChange.Operations)
                    {
                        if (operation.LinesDeleted > 0)
                        {
                            OnLineDeleted(intLineNum)
                        }
                    }
                }
Posted 11 months ago by John
Avatar

Basically I want a way to loop over the deleted lines and at each deleted line, I want to perform an action by calling a method that takes in the integer line number that was just deleted by the user. I don't know if that's possible

[Modified 11 months ago]

Answer - Posted 11 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

The operation.StartPosition.Line property has the start line index (zero-based) for the text change operation.


Actipro Software Support

Posted 11 months ago by John
Avatar

Thank you! Exactly what I was looking for!

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

Add Comment

Please log in to a validated account to post comments.