Well, here is what I did.
I have made two steps. The first step analyzes per token. I use the token stream to get the previous and/or next token. Depending on that I insert or remove whitespaces.
The second step only trims whitespaces and uses the correct indentation.
My biggest problem is the performance. In my editor a lot of things happen during the DocumentChanged event, so I try to minimize the modifications.
My method lookes like this:
public override void FormatTextRange(ActiproSoftware.SyntaxEditor.Document document, TextRange textRange)
{
document.UndoRedo.StartGroup(DocumentModificationType.AutoFormat);
// 1 - analyze per token
FormatTokens(document, textRange);
// 2 - analyze per line (indentation)
FormatLines(document, textRange);
document.UndoRedo.EndGroup();
}
And inside the methods you do your logic and replace the text like that:
document.ReplaceText(DocumentModificationType.AutoFormat, currentToken.TextRange, newText, DocumentModificationOptions.RetainSelection);
[Modified 12 years ago]
Best regards,
Tobias Lingemann.