Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Suspend the Undostack of Avalonedit?

  • I perform a massive text-change on the editor
  • i can not (or very difficult) determine when the changes begin end (the textchange is released by scrolling)
  • i dont want to be able to undo the changes

for this reasons i want to suspend the listening of the stack (or do a pop after any textchange). but

  • the stack offers no method to pop a stackelement without performing the undo
  • i dont want to clear the stack completly
  • there´s no method to detach the stack from the textdocument
  • there´s no method to suspend the listening

do you know a possibility to solve this?

like image 550
0xDEADBEEF Avatar asked Sep 28 '11 11:09

0xDEADBEEF


1 Answers

You want the undo stack to not record some changes, but don't want to be cleared it either? That would mean the contents of the undo stack might be inconsistent with the document content - when the user then presses undo, it might end up crashing or changing text other than in the expected location.

For this reason, AvalonEdit does not support this operation. We try very hard to avoid inconsistent undo stacks - for example, re-entrant updates (changing the document within a TextDocument.Changed event handler) are disallowed.

The closest you can get to disabling the undo stack is to set

document.UndoStack.SizeLimit = 0;

This will effectively disable listening for changes, but it'll also clear the undo stack.

As a side note: it is possible to 'detach' an undo stack (by setting document.UndoStack to another undo stack), but that will also clear the old undo stack.

like image 62
Daniel Avatar answered Sep 27 '22 21:09

Daniel