[157526] cannot type at end of read-only region
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java
index 6a4ae05..1a4ae19 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * Copyright (c) 2001, 2006 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -2003,9 +2003,12 @@
 
 		return getLength();
 	}
-
+	
 	public void makeReadOnly(int startOffset, int length) {
+		makeReadOnly(startOffset, length, false, false);
+	}
 
+	public void makeReadOnly(int startOffset, int length, boolean canInsertBefore, boolean canInsertAfter) {	
 		// doesn't make sense to have a readonly region of 0 length,
 		// so we'll ignore those requests
 		if (length <= 0)
@@ -2022,7 +2025,7 @@
 		// we can blindly add category, since no harm done if already
 		// exists.
 		addPositionCategory(READ_ONLY_REGIONS_CATEGORY);
-		Position newPosition = new Position(startOffset, length);
+		Position newPosition = new ReadOnlyPosition(startOffset, length, canInsertBefore);
 		try {
 			addPosition(READ_ONLY_REGIONS_CATEGORY, newPosition);
 			// FIXME: need to change API to pass in requester, so this event
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/ReadOnlyPosition.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/ReadOnlyPosition.java
new file mode 100644
index 0000000..51b5b69
--- /dev/null
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/ReadOnlyPosition.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.sse.core.internal.text;
+
+import org.eclipse.jface.text.Position;
+
+class ReadOnlyPosition extends Position {
+	private boolean fIncludeStartOffset = false;
+
+	public ReadOnlyPosition(int offset, int length, boolean includeStart) {
+		super(offset, length);
+		fIncludeStartOffset = includeStart;
+	}
+
+	public boolean overlapsWith(int offset, int length) {
+		boolean overlapsWith = super.overlapsWith(offset, length);
+		if (overlapsWith) {
+			/*
+			 * BUG157526 If at the start of the read only region and length =
+			 * 0 most likely asking to insert and want to all inserting before
+			 * read only region
+			 */
+			if (fIncludeStartOffset && (length == 0) && (this.length != 0) && (offset == this.offset)) {
+				overlapsWith = false;
+			}
+		}
+		return overlapsWith;
+	}
+}
diff --git a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java
index d453a10..f80e718 100644
--- a/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java
+++ b/bundles/org.eclipse.wst.xml.core/src/org/eclipse/wst/xml/core/internal/document/ReadOnlyController.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * Copyright (c) 2001, 2006 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -18,6 +18,7 @@
 import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
 import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
 import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
 import org.eclipse.wst.xml.core.internal.provisional.document.IDOMText;
@@ -50,7 +51,11 @@
 		if (doc == null) {
 			return;
 		}
-		doc.makeReadOnly(offset, length);
+		if (doc instanceof BasicStructuredDocument) {
+			((BasicStructuredDocument)doc).makeReadOnly(offset, length, canInsertBefore, canInsertAfter);
+		} else {
+			doc.makeReadOnly(offset, length);
+		}
 	}
 
 	static private void lock(IStructuredDocumentRegion node, boolean canInsertBefore, boolean canInsertAfter) {
@@ -61,7 +66,11 @@
 		if (doc == null) {
 			return;
 		}
-		doc.makeReadOnly(node.getStart(), node.getLength());
+		if (doc instanceof BasicStructuredDocument) {
+			((BasicStructuredDocument)doc).makeReadOnly(node.getStart(), node.getLength(), canInsertBefore, canInsertAfter);
+		} else {
+			doc.makeReadOnly(node.getStart(), node.getLength());
+		}
 	}
 
 	static private void unlock(IStructuredDocumentRegion node) {