handle deleting of empty comments

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java
index be49e46..2e81b62 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/widget/L2SimpleEditingTest.java
@@ -235,4 +235,24 @@
 		widget.insertText("Hello World");

 		assertEquals("Hello World", comment.getText());

 	}

+

+	@Test

+	public void givenAnEmptyComment_whenCaretInCommentAndHittingBackspace_shouldDeleteComment() throws Exception {

+		final Element titleElement = widget.insertElement(TITLE);

+		final Comment comment = widget.insertComment();

+		widget.deletePreviousChar();

+		assertEquals(0, titleElement.getChildCount());

+		assertFalse(comment.isAssociated());

+		assertNull(comment.getParent());

+	}

+

+	@Test

+	public void givenAnEmptyComment_whenCaretInCommentAndHittingDelete_shouldDeleteComment() throws Exception {

+		final Element titleElement = widget.insertElement(TITLE);

+		final Comment comment = widget.insertComment();

+		widget.deleteNextChar();

+		assertEquals(0, titleElement.getChildCount());

+		assertFalse(comment.isAssociated());

+		assertNull(comment.getParent());

+	}

 }

diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
index 7fc9720..119c1eb 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
@@ -350,10 +350,6 @@
 	 * Miscellaneous
 	 */
 
-	public boolean isEmpty() {
-		return getStartOffset() + 1 == getEndOffset();
-	}
-
 	@Override
 	public String toString() {
 
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java
index e87b757..3f61d96 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Node.java
@@ -116,6 +116,10 @@
 		return new ContentRange(getStartOffset(), getEndOffset());
 	}
 
+	public boolean isEmpty() {
+		return getEndOffset() - getStartOffset() == 1;
+	}
+
 	/**
 	 * Indicates whether the given offset is within the boundaries of this node. If this node is not associated with
 	 * textual content, this method returns false.
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
index ecb83b9..f29f32b 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
@@ -317,13 +317,13 @@
 				joinElementsAt(offset);
 			} else if (isBetweenMatchingElements(offset + 1)) {
 				joinElementsAt(offset + 1);
-			} else if (doc.getElementForInsertionAt(offset).isEmpty()) {
+			} else if (doc.getNodeForInsertionAt(offset).isEmpty()) {
 				// deleting the right sentinel of an empty element
 				// so just delete the whole element an move on
 				moveBy(1);
 				moveBy(-2, true);
 				deleteSelection();
-			} else if (doc.getElementForInsertionAt(offset + 1).isEmpty()) {
+			} else if (doc.getNodeForInsertionAt(offset + 1).isEmpty()) {
 				// deleting the left sentinel of an empty element
 				// so just delete the whole element an move on
 				moveBy(2, true);
@@ -346,13 +346,13 @@
 				joinElementsAt(offset);
 			} else if (isBetweenMatchingElements(offset - 1)) {
 				joinElementsAt(offset - 1);
-			} else if (doc.getElementForInsertionAt(offset).isEmpty()) {
+			} else if (doc.getNodeForInsertionAt(offset).isEmpty()) {
 				// deleting the left sentinel of an empty element
 				// so just delete the whole element an move on
 				moveBy(1);
 				moveBy(-2, true);
 				deleteSelection();
-			} else if (doc.getElementForInsertionAt(offset - 1).isEmpty()) {
+			} else if (doc.getNodeForInsertionAt(offset - 1).isEmpty()) {
 				// deleting the right sentinel of an empty element
 				// so just delete the whole element an move on
 				moveBy(-2, true);