Bug 465684: Allow initial visible region of 0, 0

Change-Id: I8f79dbf19a4ee9994f545865c499974f0644bd5a
Signed-off-by: Jonah Graham <jonah@kichwacoders.com>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
index de4b960..2028462 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -10,6 +10,7 @@
  *     Tom Eicher (Avaloq Evolution AG) - block selection mode
  *     Markus Schorn <markus.schorn@windriver.com> - shift with trailing empty line - https://bugs.eclipse.org/325438
  *     Sergey Prigogin (Google) - Bug 441827 - TextViewer.ViewerState.restore method looses caret position
+ *     Jonah Graham (Kichwa Coders) - Bug 465684 - Fix initial setVisibleRegion of 0, 0
  *******************************************************************************/
 package org.eclipse.jface.text;
 
@@ -3007,8 +3008,12 @@
 			int offset= document.getLineOffset(line);
 			int length= (visibleRegionOffset - offset) + visibleRegionLength;
 
+			// Bug 465684: It is not possible to determine the difference between a
+			// set parent document range of 0, 0 vs an unset one. So in the 0, 0 case
+			// always set the parent document range.
 			Position parentRange= childDocument.getParentDocumentRange();
-			if (offset != parentRange.getOffset() || length != parentRange.getLength()) {
+			if (offset != parentRange.getOffset() || length != parentRange.getLength()
+					|| (offset == 0 && length == 0)) {
 				childDocument.setParentDocumentRange(offset, length);
 				return true;
 			}
diff --git a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java
index ec4094d..b3481fe 100644
--- a/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java
+++ b/org.eclipse.ui.editors.tests/src/org/eclipse/ui/editors/tests/SegmentedModeTest.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 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
@@ -7,6 +7,7 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     Jonah Graham (Kichwa Coders) - Bug 465684 - Fix initial setVisibleRegion of 0, 0
  *******************************************************************************/
 package org.eclipse.ui.editors.tests;
 
@@ -16,6 +17,7 @@
 
 import org.eclipse.swt.custom.StyledText;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IFolder;
@@ -99,4 +101,38 @@
 			assertTrue(false);
 		}
 	}
+
+	/*
+	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465684
+	 */
+	public void testShowNothing() {
+		IWorkbench workbench= PlatformUI.getWorkbench();
+		IWorkbenchPage page= workbench.getActiveWorkbenchWindow().getActivePage();
+		try {
+			while (Display.getDefault().readAndDispatch()) {
+			}
+			IEditorPart part= IDE.openEditor(page, fFile);
+
+			try {
+				if (part instanceof ITextEditor) {
+					ITextEditor editor= (ITextEditor)part;
+
+					editor.showHighlightRangeOnly(true);
+					editor.setHighlightRange(0, 0, true);
+
+					Control control= (Control)part.getAdapter(Control.class);
+					if (control instanceof StyledText) {
+						StyledText styledText= (StyledText)control;
+						String text= styledText.getText();
+						assertEquals("", text);
+					}
+				}
+			} finally {
+				page.saveEditor(part, false);
+			}
+
+		} catch (PartInitException e) {
+			assertTrue(false);
+		}
+	}
 }