Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 70934

Summary: [implementation][projection] cannot set visible region length=0 in editor
Product: [Eclipse Project] Platform Reporter: Amy Wu <for.work.things>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, david_williams
Version: 3.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Amy Wu CLA 2004-07-27 16:40:06 EDT
I am working with an editor that displays only part of a document for
users to edit.  I do this by essentially calling
TextViewer#setVisibleRegion.  Sometimes the visible region I set has an
offset & length=0, which should basically mean the user can insert new
text in the visible region and the visible region grows with what the user
types.

My problem is that I can't seem to do this.  It looks like this is because
in org.eclipse.jface.text.ProjectionDocument#ensureWellFormedSegmentation
there is a check to see if the visible region lengths == 0.  If they do,
they are ignored.  I think a visible region of length 0 should be allowed for 
the scenario I just described.
Comment 1 Dani Megert CLA 2004-07-28 02:53:19 EDT
+1
Comment 2 Amy Wu CLA 2004-08-10 14:08:44 EDT
any chance this bug could be fixed for 3.0.1?  Otherwise, is there some sort 
of easy workaround?
Comment 3 Amy Wu CLA 2004-08-24 15:17:40 EDT
FYI, I have a workaround for this problem.  I basically add a " " before I 
setvisibleregion and then I delete the " " right after I set the visible 
region.  So it essentially looks a little something like:

boolean usedWorkaround = false;
if (visibleRegion.getLength == 0) {
  // add " " to document
  // visibleRegion.length = 1
  // usedWorkaround = true;
}
TextViewer.setVisibleRegion(visibleRegion)
if (usedWorkaround) {
  // delete " " that was added
}

One side effect I know of is that I do actually have to modify my document in 
the workaround, so my file is marked dirty.
Comment 4 Kai-Uwe Maetzel CLA 2004-08-25 12:07:41 EDT
I have code released to HEAD (i.e. 3.1) solving the problem. The corresponding 
test is SegmentedModeTest in org.eclipse.ui.editors.tests. We'll run with that 
for a while to find potential side effects not caught by the test suites. If 
this looks OK, the fix will go into 3.0.1 if you still think you need it.
Comment 5 Amy Wu CLA 2004-08-25 13:56:39 EDT
Yes, if the fix is good and can be included in 3.0.1, I would prefer to use 
the real fix instead of the workaround. Thanks.
Comment 6 Dani Megert CLA 2010-01-18 11:16:18 EST
This got fixed long time ago.