Updating the Undo stack on programmatic changes

SyntaxEditor for WPF Forum

Posted 9 years ago by Craig - Varigence, Inc.
Version: 11.1.0541
Avatar
We're migrating our WinForms SyntaxEditors to Wpf and we're hitting a snag with using data-binding and undo/redo.

When we used the WinForms editor and a programmatic change was made, we would do the following:

syntaxEditor.Document.ReplaceText(DocumentModificationType.ReplaceAll, 0, syntaxEditor.Document.Length, renderText);
This allowed us to update the syntax editor's text without its undo/redo stack being cleared. Additionally, it would add a UndoableModification item to its undo/redo stack.

When I try doing this with the Wpf SyntaxEditor, there appears to be a regression where updating text (that's bound to the SyntaxEditor's Text property) doesn't add a IUndoableTextChange to the UndoStack. Interestingly, the UndoStack's StackChanged event does fire, but the UndoStack remains empty.

Is this a bug?

If this is intentional, can we change this behavior to get a TextChange object added? (so programmatic changes can be undone).

If not, how might we meaningfully track programmatic changes so we can provide an undo/redo behavior for them?

Thanks,

-Craig

[Modified at 03/03/2011 04:36 PM]

Comments (3)

Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Craig,

Right now binding updates on the SyntaxEditor.Text property will call document.SetText, which does clear the undo history. If we persist all data-bound changes to the undo history, that means any change made coming from a data binding will cause the entire contents of the SyntaxEditor to be saved in the history in new undo items. That could add up in terms of memory pretty fast. This is because data binding just replaces the whole text value, it doesn't tell us if a single character was inserted, etc.

document.ReplaceText, where you specify the full range of the document, is the programmatic call you'd want to use if you wish to keep the undo history.


Actipro Software Support

Posted 9 years ago by Craig - Varigence, Inc.
Avatar
OK - that was the answer I expected. Just curious, though - if you're proposing that I use ReplaceText to preserve the undo history, couldn't the databinding's operation be changed to use ReplaceText instead of SetText (in a future release)? While using ReplaceText certainly isn't a burden, if I'm going to use it and accept the memory consequences anyway, using a binding would be more conveinent for me.

Thanks again,

-Craig
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'll make a TODO item to possibly add an option for whether it will keep the undo history or not. That way you'd be able to select which way to do it.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) 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.