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!