Bug 448416

Summary: [projection] nested folding is only partially supported
Product: [Eclipse Project] Platform Reporter: Bill Fenlason <billfenlason>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P3 CC: daniel_megert
Version: 4.4   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
modified DefineFoldingRegionAction class from org.eclipse.ui.examples.javaeditor.JavaEditor none

Description Bill Fenlason CLA 2014-10-22 15:40:34 EDT
Created attachment 248114 [details]
modified DefineFoldingRegionAction class from org.eclipse.ui.examples.javaeditor.JavaEditor

The current projection / folding support does not deal with (or even consider) multiple folding regions which begin on the same line.  

Using the java editor example (org.eclipse.ui.examples.javaeditor, which in essence simply converts a selected block into a folding region), one can define multiple folding regions which begin on the same line.  When the single annotation is collapsed, one of the regions is apparently randomly selected for the collapse.

From a UI perspective, I think the choice should be to either to disallow the ability to define more than one folding region beginning on the same line, or to provide some visual indication and appropriate actions for collapse and expand.      

It seems to me that a solution for the general case is preferable, such as providing a different color for the annotation, choosing the smallest region to expand/contract first, etc.  Currently, the code apparently ignores multiple folding positions with the same starting point.

Ultimately character based folding rather than line based folding should be designed and implemented, and if so, disallowing multiple folding regions which begin with the same character is more reasonable.

The java editor example does not address this issue.  I have attached a modified version of the DefineFoldingRegionAction class from the example which deletes existing annotations which start on the same line as the newly defined region.  This enhances the demonstrated function by providing a way to delete existing folding regions (selecting the action on a line beginning a folding region but without selecting a block), replace existing regions and requiring new folding regions to be more than one line in length.  If the examples are maintained, perhaps these changes might be useful.

This is surely a duplicate of one or more of the dozens of folding bugs and enhancement requests.