How to Suspend the Undostack of Avalonedit?
Asked Answered
A

1

6
  • 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?

Allister answered 28/9, 2011 at 11:5 Comment(0)
J
10

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.

Jonijonie answered 28/9, 2011 at 16:59 Comment(3)
oh, i havnt realized this. ok, then i have to go another way: sum all the changes to an undogroup in order to avoid thousands of useless elements in the undostack. i will test it in a testing-branch of my project. thanks for your helpAllister
If there's no easy way to figure out the end of the operation, you might want to look at UndoStack.StartContinuedUndoGroup().Jonijonie
Visual Studio 2022 actually suggested this for me: I started to type this line right before document.BeginUpdate(), and it suggested this. document.UndoStack.SizeLi[mit = 0]Wanigan

© 2022 - 2024 — McMap. All rights reserved.