Reformat Text / Code ?

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by Richard Beyer - KBS Leipzig
Avatar
Hi,

is there a possibility to perform an action like "reformat code or text"

my intention is to reformat some xml texts


greetings
richard

Comments (9)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
We have stubs of methods you can implement in your SyntaxLanguage class to do formatting. Both the FormatDocument and FormatSelection methods call a virtual FormatTextRange method. You can place functionality in a FormatTextRange override to do the actual formatting. I don't believe any of our current languages have implementations of this yet but that is where you would do it.

If you do that, you should also override FormattingSupported to return true.


Actipro Software Support

Posted 18 years ago by Richard Beyer - KBS Leipzig
Avatar
thank you, i'll try this
Posted 17 years ago by tobias weltner
Avatar
I am trying to implement this and inserted a FormatTextRange sub into my language.
However, I am wondering what I am supposed to do inside of this sub to do the actual formatting. Do you have a code sample for me?
Posted 17 years ago by tobias weltner
Avatar
I managed to get the code working.
However, when I format the code, the caret position is not retained even though I set the option RetainSelection. I assume this is because the caret position was inside the changed text.
I therefore manually reset the caret position which works fine. However, now I see the following:
- when I call FormatDocument, the editor scrolls to the end of the document
- a split-second later, the original position is retained through my own code which I execute right after FormatDocument returns.

This is all understandable and ok. However, I am looking for a way to prevent the editor from scrolling temporarily to remove the unwanted flicker. I worked around it by temporarily setting visible=false. I can reduce the flicker this way but not completely remove it. So I am wondering if there is something else I can try. I tried SuspendLayout/Resumelayout but this won't work. Any hints? Thx!
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
In that method override you'll just want to do a Document.ReplaceText as the main final operation.

What about trying Suspend/Resume painting on the SyntaxEditor control to help with the flicker?


Actipro Software Support

Posted 17 years ago by tobias weltner
Avatar
that did it...! thx!
Posted 17 years ago by Lee Grissom - Quest Software, Inc.
Avatar
How did you keep the editor from scrolling after replacing the text? Here's what I wrote, but it doesn't prevent the Editor control from scrolling.

C# code
int caretOffset = Editor.Caret.Offset;
Editor.SuspendPainting();
Editor.Document.ReplaceText(DocumentModificationType.ReplaceAll,
0,
Editor.Document.Length,
Editor.Document.Text));
Editor.Caret.Offset = caretOffset;
Editor.ResumePainting();
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Maybe store the selected view's FirstVisibleDisplayLineIndex and FirstVisibleX, then restore before resuming painting?


Actipro Software Support

Posted 17 years ago by Lee Grissom - Quest Software, Inc.
Avatar
Thanks, that seems to do the trick.
The latest build of this product (v24.1.1) 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.