Smart Indent and Undo/Redo Conflicts

SyntaxEditor for Windows Forms Forum

Posted 7 years ago by Cody Thompson - Space Systems Engineer, a.i. solutions
Version: 12.1.0302
Avatar

Hello,

So I have implemented a smart indentation scheme and it works wonderfully. It is currently implemented in the OnDocumentTextChanged() method override. However, there seems to be an issue when a person undoes or redoes things, in that the undo and redo actions fire OnDocumentTextChanged() with the same DocumentModification types as when the code was first written. This is a problem in that it tries to execute the smart indentation code when undoing/redoing, which results in an Actipro exception being thrown from the UndoRedo stack. I've tried finding a way to detect whether something is an undo / redo action in OnDocumentTextChanged(), but I don't think there is a way to detect it.

What would you recommend doing to alleviate this issue? Is there some way to detect whether something is an undo action from inside the OnDocumentTextChanged() method? If not, is there a better place to do smart indentation logic?

Thanks in advance.

Comments (2)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cody,

You can check for flags like:

e.Modification.HasFlag(DocumentModificationFlags.Undo)

And a related one for redo.  Then you can skip your logic if you see either those.


Actipro Software Support

Posted 7 years ago by Cody Thompson - Space Systems Engineer, a.i. solutions
Avatar

This fixed my issue perfectly. Thank you so much!

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

Add Comment

Please log in to a validated account to post comments.