AvalonEdit :: How do I preserve current state in the UndoStack?
Asked Answered
G

1

12

I am currently working on implementing AvalonEdit in an HTML WYSIWYG/"Source Code" side-by-side editor. When the user switches from Design Mode (a RichTextBox) to Source Mode (AvalonEdit TextEditor) the XAML from the RTB is converted to HTML and written to the TextEditor.Document.Text property.

This apparently wipes out the undo stack.

How can I push the state of the Document to the UndoStack so the user can "go back"? I tried wrapping the write operation in a RunUpdate() IDisposable, but that didn't work:

using (var _ = TextEditor.Document.RunUpdate())
{
   TextEditor.Document.Text = html;
}

Any assistance would be greatly appreciated.

Giffy answered 13/4, 2015 at 23:9 Comment(0)
L
0

Since this is a couple years late, I'm not sure if it answers the question directly. However, the current release of AvalonEdit functions such that setting TextEditor.Text will clear the undo stack, but modifying TextEditor.Document.Text will not. (This runs counter to the behavior observed by the asker, so perhaps it has changed in the couple years since). Looking at the source code, TextEditor.Document.Text appears to execute code equivalent to

this.Replace(0, this.TextLength, value);

so perhaps a similar call would work even on older versions of the library.

Laky answered 22/12, 2015 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.