SyntaxEditor CustomLineNumbering

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Tim Strong
Avatar
I have checked all your forums and documentation on CustomLineNumbering and am still not getting the issue below resolved. I have tried coding inside events _KeyTyped, KeyTyping, KeyPress, KeyDown, and even overriding ProcessCmdKey(...), but with no success, so I need help and quickly.

I have a custom code editor with Custom Line Numbering which when I hit the "\r" or Key.Enter should increment the next line by the factor set.

For instance:
10
20
30
:
:

However, when I try to recompute what the CustomLineNumbering value should be and try to reset it for that line, the default values of auto line numbering take over (i.e. 10,11,12,13...)... I want to displace these auto-line numbers with my own.

Is there some code you would recommend to implement this?
What I have so far is something like (c#.net):

int iCurrentLinePosition = CodeEditor.Caret.Position.Line;
DocumentLine dLine = CodeEditor.Document.Lines[iCurrentLinePosition];
int iOldLineNumberFromCaretPosition = Convert.ToInt32(dLine.CustomLineNumber);
int iNewLineNo = iOldLineNumberFromCaretPosition + (int)this.AutoLineNumberingIncAmount;
dLine = CodeEditor.Document.Lines[iCurrentLinePosition + 1];
dLine.CustomLineNumber = iNewLineNo.ToString();

However, when I try to implement in any of the Key* events, my calculated Custom Numbering is still overridden by your auto-line numbering incremented by 1's...

Any suggestions would be appreciated ASAP.

Thanks,

Tim

Comments (6)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tim,

You should probably do this in the SyntaxEditor.DocumentTextChanged event since that occurs after we've updated our lines from ANY operation. You are just trying to catch key events but there are things like drag/drop, etc. to consider as well.

That event even tells you (via the modification) which range of document lines were deleted and inserted.

Let us know if that helps.


Actipro Software Support

Posted 13 years ago by Tim Strong
Avatar
No, I don't think so... Well, there's no way to trap for KeyData on the event of DocumentTextChanged, so how will I trap for Key.Enter or Key.Delete in order to recalculate the renumber?

if ((e.KeyData == Keys.Enter) && (AP_CodeEditor.SelectedView.Selection.EndOffset > 0))
{
// Massage event args to handle auto-line numbering properly
int iCurrentLinePosition = CodeEditor.Caret.Position.Line;
DocumentLine dLine = CodeEditor.Document.Lines[iCurrentLinePosition];
int iOldLineNumberFromCaretPosition = Convert.ToInt32(dLine.CustomLineNumber);
int iNewLineNo = iOldLineNumberFromCaretPosition + (int)this.AutoLineNumberingIncAmount;
dLine = CodeEditor.Document.Lines[iCurrentLinePosition + 1];
dLine.CustomLineNumber = iNewLineNo.ToString();
}

e.KeyData property does not exist for CodeEditor_DocumentTextChanged(object sender, ActiproSoftware.SyntaxEditor.DocumentModificationEventArgs e) so how do I trap here?

Please post sample code and where to handle inside which method/event with proper key event trapping.

Thanks,

T
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The modification tells you how many lines are deleted and then inserted for that modification. In addition you can look at the DocumentModification.Type property which will return Enter when your press Enter. There are a bunch of other types of modifications that can happen as well and it tells you what the modification was.

I'm not clear on exactly what scenarios you need to renumber based on what you've posted so far. However the event I indicated is the place to do this sort of thing. Especially since you will know exactly how many lines are deleted/inserted and where the modification occurred.


Actipro Software Support

Posted 13 years ago by Tim Strong
Avatar
Ok... Got It!! No need to re-respond. I just wanted to say Thanks for the thoughts. After re-reading your messages, it put me on the right track and thought process... Once I changed my thinking to what you indicated above, I was able to get what I needed to work in just a few minutes.

Thanks for your great support! Keep up the good work!.

T
Posted 13 years ago by Tim Strong
Avatar
Ok... Got It!! No need to re-respond. I just wanted to say Thanks for the thoughts. After re-reading your messages, it put me on the right track and thought process... Once I changed my thinking to what you indicated above, I was able to get what I needed to work in just a few minutes.

Thanks for your great support! Keep up the good work!.

T
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Great Tim... yes we've tried to make the DocumentModification provide as much information as possible about what is changed in the document so that you can update things like custom line numbering as necessary.


Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.