provide compound edit that contains the committed/rolled back work

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/undo/EditStackTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/undo/EditStackTest.java
index a4de587..d77453c 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/undo/EditStackTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/undo/EditStackTest.java
@@ -10,6 +10,7 @@
  *******************************************************************************/
 package org.eclipse.vex.core.internal.undo;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
@@ -245,6 +246,36 @@
 		assertTrue("undo edit3", edit3.undoCalled);
 	}
 
+	@Test
+	public void threeEditsCommitted_shouldProvideOffsetAfterLastEdit() throws Exception {
+		final EditStack stack = new EditStack();
+		final MockEdit lastEdit = new MockEdit();
+		lastEdit.offsetAfter = 123;
+
+		stack.beginWork();
+		stack.apply(new MockEdit());
+		stack.apply(new MockEdit());
+		stack.apply(lastEdit);
+		final IUndoableEdit committedEdit = stack.commitWork();
+
+		assertEquals(123, committedEdit.getOffsetAfter());
+	}
+
+	@Test
+	public void threeEditsRolledBack_shouldProvideOffsetBeforeFirstEdit() throws Exception {
+		final EditStack stack = new EditStack();
+		final MockEdit firstEdit = new MockEdit();
+		firstEdit.offsetBefore = 123;
+
+		stack.beginWork();
+		stack.apply(firstEdit);
+		stack.apply(new MockEdit());
+		stack.apply(new MockEdit());
+		final IUndoableEdit rolledbackEdit = stack.rollbackWork();
+
+		assertEquals(123, rolledbackEdit.getOffsetBefore());
+	}
+
 	private static class MockEdit implements IUndoableEdit {
 
 		public boolean redoCalled;
@@ -253,6 +284,8 @@
 		private final boolean canUndo;
 		private final boolean canRedo;
 		public boolean canCombine;
+		public int offsetBefore;
+		public int offsetAfter;
 
 		public MockEdit() {
 			this(true, true);
@@ -290,11 +323,11 @@
 		}
 
 		public int getOffsetBefore() {
-			return 0;
+			return offsetBefore;
 		}
 
 		public int getOffsetAfter() {
-			return 0;
+			return offsetAfter;
 		}
 	}
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/EditStack.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/EditStack.java
index fd21ad9..cdb9143 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/EditStack.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/EditStack.java
@@ -75,20 +75,22 @@
 		pendingEdits.push(new CompoundEdit());
 	}
 
-	public void commitWork() {
+	public IUndoableEdit commitWork() {
 		if (pendingEdits.isEmpty()) {
 			throw new CannotApplyException("No edit pending, cannot commit!");
 		}
 
-		apply(pendingEdits.pop());
+		return apply(pendingEdits.pop());
 	}
 
-	public void rollbackWork() {
+	public IUndoableEdit rollbackWork() {
 		if (pendingEdits.isEmpty()) {
 			throw new CannotUndoException("No edit pending, cannot rollback!");
 		}
 
-		pendingEdits.pop().undo();
+		final CompoundEdit work = pendingEdits.pop();
+		work.undo();
+		return work;
 	}
 
 	public boolean inTransaction() {