handle deleting single characters in text

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 3ab70b0..cd52547 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
@@ -55,4 +55,23 @@
 		assertEquals(titleElement.getStartOffset(), widget.getCaretOffset());

 		assertSame(rootElement, widget.getCurrentElement());

 	}

+

+	@Test

+	public void givenAnElementWithText_whenHittingBackspace_shouldDeleteLastCharacter() throws Exception {

+		final Element titleElement = widget.insertElement(new QualifiedName(null, "title"));

+		widget.insertText("Hello");

+		widget.deletePreviousChar();

+		assertEquals("Hell", titleElement.getText());

+		assertEquals(titleElement.getEndOffset(), widget.getCaretOffset());

+	}

+

+	@Test

+	public void givenAnElementWithText_whenHittingPos1AndDelete_shouldDeleteFirstCharacter() throws Exception {

+		final Element titleElement = widget.insertElement(new QualifiedName(null, "title"));

+		widget.insertText("Hello");

+		widget.moveBy(-5);

+		widget.deleteNextChar();

+		assertEquals("ello", titleElement.getText());

+		assertEquals(titleElement.getStartOffset() + 1, widget.getCaretOffset());

+	}

 }

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 dbb3106..2b3d768 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
@@ -338,7 +338,6 @@
 	}
 
 	public void deletePreviousChar() throws DocumentValidationException {
-
 		if (hasSelection()) {
 			deleteSelection();
 		} else {
@@ -372,13 +371,12 @@
 				}
 			}
 		}
-
 	}
 
 	public void deleteSelection() {
 		try {
 			if (hasSelection()) {
-				applyEdit(new DeleteEdit(document, new Range(getSelectionStart(), getSelectionEnd())), getSelectionStart());
+				applyEdit(new DeleteEdit(document, new Range(getSelectionStart(), getSelectionEnd() - 1)), getSelectionStart());
 				this.moveTo(getSelectionStart());
 			}
 		} catch (final DocumentValidationException e) {