Undo/Redo Stack

SyntaxEditor for WPF Forum

Posted 8 years ago by James Zheng
Version: 16.1.0630
Avatar

Hi Actipro,

Is it possible to make a text change without affecting the undo/Redo stack and also the isModified flag?

Thanks and regards,

James Zheng

Comments (13)

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

Hi James,

I'm sorry but that isn't possible since that would corrupt the undo history.  Can you describe your scenario that you are trying to achieve?


Actipro Software Support

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

In my application, I'm using MVVM pattern, the model is changed remotely by code behind. We want to update the view, but don't want user to undo the change. For example, the renaming of variable names from other locations other than the Actipro editor. These variables could be used in other types of editors and locations.

 

Regards,

James Zheng

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

Hi James,

In that case I would probably suggest just doing a full editor.Document.SetText and replace the text.  This will wipe out the undo and mark everything as if a new document was opened.  If you don't want them to be able to undo the change you made, that seems like the only way to go.


Actipro Software Support

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

I am proposing the syntax editor to have the ability to group items into one undo item. When users choose to undo, all the items in this group can be done in one single undo action. Following could be the work flow:

1. Users apply changes programmatically (in code)  and pass in an additional argument indicating if this change is going to be grouped with the last change in the undo stack.

2. If grouping with the last change, this change can be undone together with the last change in undo stack when one undo action is performed.

3. Changes to be grouped must be consecutive. And the number of items in the group is not limited

4. If the change comes from users directly changing content in the editor, the change is not grouped with the last change in the undo stack.

With this implementation, it adds values and dynamism to the undo/redo feature of the syntax editor, while making sure the undo stack is not corrupted. And most importantly, it serves my clients well. :)

Please consider if this is possible.

Thanks and regards,

James Zheng

[Modified 8 years ago]

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

Hi James,

If we added this feature (the ability to merge a text change into the last undo stack text change if there is one), would it be done via a new ITextChangeOptions.CanMergeIntoPreviousChange property when true?  Undoing after the programmatic text change was applied would undo it and the prior text change on the undo stack, since they would effectively be merged into the same undoable text change that would take on the text change type of the original text change.  If no previous text change is available, then no merge would happen and this programmatic text change would be undoable itself.  Does that all sound correct per your needs?


Actipro Software Support

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

Sorry for the late reply. Your description above looks great and thanks again for the support.

I've a little request. Could we query back to the undo history to check if the current undo action to be poped has CanMergeIntoPreviousChange property set to true when this action was placed onto the undo history? We'll need to prompt users of some unexpected programmatic undo actions to be performed before undo.

Regards,

James Zheng

[Modified 8 years ago]

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

Hi James,

We will have this feature added for the next maintenance release.  We will add a ITextChangeOptions.CanMergeIntoPreviousChange property you'd set to true (via the options you pass when creating a text change).  Then a ITextChange.IsMerged property will indicate if the text change is the result of two or more text changes that were merged.


Actipro Software Support

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

Thanks for the help!

Regards,

James Zheng

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

I've been implementing the merged undo feature. But I cannot figure out how the text selection will behave after I undo the merged changes. Will it be the selection of the 1st change, the last change or the selection before undo.

Regards,

James zheng

[Modified 8 years ago]

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

Hi James,

Behind the scenes, it's just chaining the additional text change operations onto the original text change.  So nothing as far as selection after undo will be altered by merging in more text change operations.  The selection after undo will still be based on the original text change.


Actipro Software Support

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

Below are the steps to reproduce.

Steps:

1. Start with no selection

2. Apply a list of merged text line replace changes with RetainSelection set to true

3. Undo

4. Found that if the caret position is on any of the lines that are part of the merged change, the whole line will be selected. (?)

5. If the caret position is not on any of the lines that are part of the merged change, the line won't be selected.

Exptect result:

The first changed line in the merged change list should be selected after undo, since it's a text replacement. It should not be affected by the caret position before undo.

Below is my change option:

var options = new TextChangeOptions();

options.CanMergeIntoPreviousChange = true;

options.OffsetDelta = TextChangeOffsetDelta.SequentialOnly;

options.RetainSelection = true;

var change = CreateTextChange(TextChangeTypes.AutoReplace, options);
   

I made a change to 'options.RetainSelection = false;'. After undo, the line which was the first change in the merged change list will always be selected. This behavior is expected. But the question remains. How will RetainSelection affect the text selection after undo?

RetainSelection was set to true, so that the text selection won't be deselected after the merged change.

Regards,

James Zheng

[Modified 8 years ago]

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

Hi James,

For complex scenarios like this, please always email our support address with a new simple sample project that repros the scenario.  That way we can see exactly what you see and debug anything that needs to be looked at.  We also can then use the sample to verify that things are working per your needs.  Kindly put one together and in your email to us, reference this thread and rename the .zip file extension of what you send so it doesn't get spam blocked.

RetainSelection is meant for the original text change, saying don't move the caret to the end of the last operation when it is applied.  I don't believe it generally affects undo.


Actipro Software Support

Posted 8 years ago by James Zheng
Avatar

Hi Actipro,

Understand. I've emailed you the steps to reproduce together with a test project. Please look for an email titled 'RE: Undo/Redo Stack'.

Regards,

James Zheng

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.