From c14b730c2e29c62fc3cffc784a14689d28dafa89 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 28 May 2012 11:34:01 +0200 Subject: [PATCH] Allow secondary view contents to prevent the CodeEditor from clearing the undo stack when switching the active view. --- .../AvalonEdit.AddIn/Src/CodeEditor.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs index c8364fa81a..34930797e0 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs @@ -304,11 +304,29 @@ namespace ICSharpCode.AvalonEdit.AddIn NewLineConsistencyCheck.StartConsistencyCheck(this); } + bool documentFirstLoad = true; + bool clearUndoStackOnSwitch = true; + + /// + /// Gets/Sets whether to clear the undo stack when reloading the document. + /// The default is true. + /// http://community.sharpdevelop.net/forums/t/15816.aspx + /// + public bool ClearUndoStackOnSwitch { + get { return clearUndoStackOnSwitch; } + set { clearUndoStackOnSwitch = value; } + } + void ReloadDocument(TextDocument document, string newContent) { var diff = new MyersDiffAlgorithm(new StringSequence(document.Text), new StringSequence(newContent)); document.Replace(0, document.TextLength, newContent, diff.GetEdits().ToOffsetChangeMap()); - document.UndoStack.ClearAll(); + + if (this.ClearUndoStackOnSwitch || documentFirstLoad) + document.UndoStack.ClearAll(); + + if (documentFirstLoad) + documentFirstLoad = false; } public event EventHandler LoadedFileContent;