Author: mkrueger
Date: 2008-02-18 11:55:13 -0500 (Mon, 18 Feb 2008)
New Revision: 96078
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
Log:
* Mono.TextEditor/Document.cs, Mono.TextEditor/TextEditorData.cs,
Mono.TextEditor/TextEditor.cs: Fixed undo/redo bug.
Modified: trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog
===================================================================
--- trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-18
16:51:08 UTC (rev 96077)
+++ trunk/monodevelop/main/src/addins/Mono.Texteditor/ChangeLog 2008-02-18
16:55:13 UTC (rev 96078)
@@ -1,5 +1,10 @@
2008-02-18 Mike Krüger <[EMAIL PROTECTED]>
+ * Mono.TextEditor/Document.cs, Mono.TextEditor/TextEditorData.cs,
+ Mono.TextEditor/TextEditor.cs: Fixed undo/redo bug.
+
+2008-02-18 Mike Krüger <[EMAIL PROTECTED]>
+
* Mono.TextEditor/DefaultEditActions.cs, Mono.TextEditor/Document.cs,
Mono.TextEditor/TextEditorData.cs, Mono.TextEditor/TextEditor.cs:
Worked
on undo/redo.
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
2008-02-18 16:51:08 UTC (rev 96077)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/Document.cs
2008-02-18 16:55:13 UTC (rev 96078)
@@ -269,17 +269,27 @@
doc.Remove (args.Offset,
args.Value.Length);
if (!String.IsNullOrEmpty (text))
doc.Insert (args.Offset, text);
- if (UndoDone != null)
- UndoDone (this, EventArgs.Empty);
+ OnUndoDone ();
}
public virtual void Redo (Document doc)
{
doc.Replace (args.Offset, args.Count,
args.Value);
- if (RedoDone != null)
- RedoDone (this, EventArgs.Empty);
+ OnRedoDone ();
}
+
+ protected virtual void OnUndoDone ()
+ {
+ if (UndoDone != null)
+ UndoDone (this, EventArgs.Empty);
+ }
public event EventHandler UndoDone;
+
+ protected virtual void OnRedoDone ()
+ {
+ if (UndoDone != null)
+ UndoDone (this, EventArgs.Empty);
+ }
public event EventHandler RedoDone;
}
@@ -315,6 +325,7 @@
for (int i = operations.Count - 1; i >= 0; i--)
{
operations[i].Undo (doc);
}
+ OnUndoDone ();
}
public override void Redo (Document doc)
@@ -322,6 +333,7 @@
foreach (UndoOperation operation in
this.operations) {
operation.Redo (doc);
}
+ OnRedoDone ();
}
}
@@ -417,18 +429,23 @@
this.RequestUpdate (new UpdateAll ());
this.CommitDocumentUpdate ();
}
-
+ int atomicUndoLevel;
public void BeginAtomicUndo ()
{
if (currentAtomicOperation == null) {
- currentAtomicOperation = new AtomicUndoOperation ();
+ Debug.Assert (atomicUndoLevel == 0);
+ currentAtomicOperation = new
AtomicUndoOperation ();
OnBeginUndo ();
}
+ atomicUndoLevel++;
}
public void EndAtomicUndo ()
{
- if (currentAtomicOperation != null) {
+ atomicUndoLevel--;
+ Debug.Assert (atomicUndoLevel >= 0);
+
+ if (atomicUndoLevel == 0 && currentAtomicOperation !=
null) {
if (currentAtomicOperation.Operations.Count >
1) {
undoStack.Push (currentAtomicOperation);
OnEndUndo (currentAtomicOperation);
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
2008-02-18 16:51:08 UTC (rev 96077)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditor.cs
2008-02-18 16:55:13 UTC (rev 96078)
@@ -338,19 +338,25 @@
public TextEditorDataState (TextEditor editor,
Document.UndoOperation operation, int caretPos, ISegment selection)
{
- this.editor = editor;
+ this.editor = editor;
+ this.caretPos = caretPos;
+ this.selection = selection;
operation.UndoDone += delegate {
- oldPos = editor.Caret.Offset;
- oldSelection = editor.SelectionRange;
+ this.oldPos = editor.Caret.Offset;
+ this.oldSelection =
editor.SelectionRange;
- editor.Caret.Offset = caretPos;
- editor.SelectionRange = selection;
+ editor.SelectionRange = this.selection;
+ editor.Caret.PreserveSelection = true;
+ editor.Caret.Offset = this.caretPos;
+ editor.Caret.PreserveSelection = false;
};
operation.RedoDone += delegate {
- editor.Caret.Offset = oldPos;
- editor.SelectionRange = oldSelection;
+ editor.SelectionRange =
this.oldSelection;
+ editor.Caret.PreserveSelection = true;
+ editor.Caret.Offset = this.oldPos;
+ editor.Caret.PreserveSelection = false;
};
}
}
Modified:
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
===================================================================
---
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
2008-02-18 16:51:08 UTC (rev 96077)
+++
trunk/monodevelop/main/src/addins/Mono.Texteditor/Mono.TextEditor/TextEditorData.cs
2008-02-18 16:55:13 UTC (rev 96078)
@@ -215,6 +215,7 @@
{
if (!IsSomethingSelected)
return;
+ document.BeginAtomicUndo ();
ISegment selection = SelectionRange;
bool needUpdate = this.selectionStart.Segment !=
this.selectionEnd.Segment;
if (Caret.Offset > selection.Offset)
@@ -224,6 +225,7 @@
if (needUpdate)
Document.RequestUpdate (new LineToEndUpdate
(Document.OffsetToLineNumber (selection.Offset)));
ClearSelection();
+ document.EndAtomicUndo ();
if (needUpdate)
Document.CommitDocumentUpdate ();
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches