Find/Replace needs access to the raw content with element markers.
Otherwise, the offsets found with Find/Replace will not match with the
offsets in the actual content.

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ContentTest.java b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ContentTest.java
index 34fa2ff..4d7002f 100644
--- a/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ContentTest.java
+++ b/org.eclipse.vex.core.tests/src/org/eclipse/vex/core/internal/dom/ContentTest.java
@@ -189,4 +189,18 @@
 		content.removePosition(position);

 		assertFalse(position.isValid());

 	}

+

+	@Test

+	public void rawTextContainsElementMarkers() throws Exception {

+		content.insertElementMarker(0);

+		content.insertElementMarker(0);

+		content.insertText(1, "Hello World");

+		content.insertElementMarker(6);

+

+		assertFalse(content.getText().equals(content.getRawText()));

+		assertEquals(content.getText().length() + 3, content.getRawText().length());

+		assertFalse(content.getText().charAt(0) == content.getRawText().charAt(0));

+		assertEquals(content.getText(1, 5), content.getRawText(1, 5));

+		assertEquals(content.getText().substring(0, 5), content.getRawText(1, 5));

+	}

 }

diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Content.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Content.java
index 49ab183..11a1dd6 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Content.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Content.java
@@ -68,6 +68,26 @@
 	public String getText();
 
 	/**
+	 * Get the plain text of a region of this content. The plain text does also contain the element markers in this
+	 * content.
+	 * 
+	 * @param offset
+	 *            Offset at which the substring begins.
+	 * @param length
+	 *            Number of characters to consider in this content.
+	 * @return the text of the given region including element markers
+	 */
+	public String getRawText(final int offset, final int length);
+
+	/**
+	 * Get the whole plain text of this content. The plain text does not contain any information about the element
+	 * markers in this content.
+	 * 
+	 * @return the whole text including element markers
+	 */
+	public String getRawText();
+
+	/**
 	 * Inserts the given content into this content at the given offset.
 	 * 
 	 * @param offset
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
index 915eb15..6458a15 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
@@ -369,15 +369,6 @@
 		return publicID;
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.vex.core.internal.dom.IVEXDocument#getRawText(int, int)
-	 */
-	public String getRawText(final int startOffset, final int endOffset) {
-		return content.getText(startOffset, endOffset - startOffset);
-	}
-
 	public Element getRootElement() {
 		return rootElement;
 	}
@@ -390,6 +381,10 @@
 		return content.getText(startOffset, endOffset - startOffset);
 	}
 
+	public String getRawText(final int startOffset, final int endOffset) {
+		return content.getRawText(startOffset, endOffset - startOffset);
+	}
+
 	public Validator getValidator() {
 		return validator;
 	}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/GapContent.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/GapContent.java
index b2da67a..423fb3d 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/GapContent.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/GapContent.java
@@ -205,6 +205,30 @@
 		}
 	}
 
+	public String getRawText() {
+		return getRawText(0, getLength());
+	}
+
+	public String getRawText(final int offset, final int length) {
+		assertOffset(offset, 0, getLength() - length);
+		assertPositive(length);
+
+		final StringBuilder result = new StringBuilder(length);
+		if (offset + length < gapStart) {
+			appendRawText(result, offset, length);
+		} else if (offset >= gapStart) {
+			appendRawText(result, offset - gapStart + gapEnd, length);
+		} else {
+			appendRawText(result, offset, gapStart - offset);
+			appendRawText(result, gapEnd, offset + length - gapStart);
+		}
+		return result.toString();
+	}
+
+	private void appendRawText(final StringBuilder stringBuilder, final int offset, final int length) {
+		stringBuilder.append(content, offset, length);
+	}
+
 	public void insertContent(final int offset, final Content content) {
 		assertOffset(offset, 0, getLength());
 
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
index 2767c7f..4ebe963 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
@@ -777,20 +777,7 @@
 
 				@Override
 				protected CharSequence getDocument() {
-					return new CharSequence() {
-
-						public CharSequence subSequence(final int start, final int end) {
-							return document.getRawText(start, end);
-						}
-
-						public int length() {
-							return document.getLength();
-						}
-
-						public char charAt(final int index) {
-							return document.getCharacterAt(index);
-						}
-					};
+					return document.getRawText(document.getStartOffset(), document.getEndOffset());
 				}
 
 				@Override