This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 144296 - Code folding GUI is broken for the last collapsed folds with innerlevel >0
Summary: Code folding GUI is broken for the last collapsed folds with innerlevel >0
Alias: None
Product: editor
Classification: Unclassified
Component: Code folding (show other bugs)
Version: 6.x
Hardware: Macintosh (x86) All
: P3 blocker (vote)
Assignee: Miloslav Metelka
Depends on:
Reported: 2008-08-18 18:23 UTC by emi
Modified: 2008-09-10 17:21 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:

Screenshot of the bad GUI with folding. Note the extra horizontal line. (3.80 KB, image/png)
2008-08-18 18:24 UTC, emi

Note You need to log in before you can comment on or make changes to this bug.
Description emi 2008-08-18 18:23:40 UTC
Try pasting this in the IDE:

class A{
    class B{
        class C{

and then collapse "class C". You'll see a bad GUI artifact for the last fold "mark". The problem being it still draws an
extra horizontal line to connect to "something" only that it doesn't have what to.

The same problem happens with Javascript for example:

function a(){
  function b(){

after you collapse "b()".

The bug seems to be in CodeFoldingSideBar as it always draws the two horizontal lines if getInnerLevel() > 0. Looks to
me like PaintInfo doesn't have enough information to cover this situation (folded, PAINT_MARK,InnerLevel>0 with nothing
following to "connect" visually to).

My patch against CodeFoldingSideBar involves separating SINGLE_PAINT_MARK from PAINT_MARK on collapsed folds just to
indicate this situation. Basically if a collapsed fold has all the parents ending on the same row (that is, no
PAINT_END_MARK or PAINT_LINE will follow on the next line) it must be called SINGLE_PAINT_MARK, otherwise PAINT_MARK .

Sorry for the inlined patch, I used diff, not hg to produce it.

@@ -301,9 +301,25 @@
                     viewRect = viewShape.getBounds();
                     y = viewRect.y + viewRect.height;
                     boolean isSingleLineFold = startViewIndex == endViewIndex;
+                    //emi: the check bellow seems to be redundant, fold.isCollaped determines isSingleLineFold to be true
                     if (fold.isCollapsed() || isSingleLineFold){
+                        boolean foldedSinglePaint = fold.isCollapsed(); //parents end here too ?
+                        if(foldedSinglePaint){
+                            //see if the parents ends on the same line and mark it as SINGLE_PAINT_MARK 
+                            int off = fold.getEndOffset();
+                            int rowEnd = javax.swing.text.Utilities.getRowEnd(component, off);
+                            Fold parent = fold.getParent();
+                            while(parent!=null && !FoldUtilities.isRootFold(parent)){
+                                if(rowEnd!=javax.swing.text.Utilities.getRowEnd(component, parent.getEndOffset())){
+                                    foldedSinglePaint = false;
+                                    break;
+                                }
+                                parent = parent.getParent();
+                            }
+                        }
+                        boolean singleMarkKind = fold.isCollapsed() ? foldedSinglePaint : isSingleLineFold;
                         map.put(new Integer(viewRect.y), 
-                            new CodeFoldingSideBar.PaintInfo((isSingleLineFold?SINGLE_PAINT_MARK:PAINT_MARK), level,
viewRect.y, viewRect.height, fold.isCollapsed()));
+                            new CodeFoldingSideBar.PaintInfo((singleMarkKind?SINGLE_PAINT_MARK:PAINT_MARK), level,
viewRect.y, viewRect.height, fold.isCollapsed()));
@@ -534,7 +550,7 @@
                     if (paintInfo.getInnerLevel() > 0){ //[PENDING]
                         g.drawLine(lineX, y, lineX, markY);
-                        g.drawLine(lineX, markY + markSize, lineX, y + height);
+                        if (paintOperation != CodeFoldingSideBar.SINGLE_PAINT_MARK) g.drawLine(lineX, markY + markSize,
lineX, y + height);
                     visibleMarks.add(new Mark(markX, markY, markSize, isFolded));
                 } else if (paintOperation == PAINT_LINE){
Comment 1 emi 2008-08-18 18:24:55 UTC
Created attachment 67727 [details]
Screenshot of the bad GUI with folding. Note the extra horizontal line.
Comment 2 Jan Becicka 2008-09-01 13:36:28 UTC
Bug report with patch. Milo, please take a look at it. Thanks.
Comment 3 Vitezslav Stejskal 2008-09-09 15:16:20 UTC
Patch applied, thanks. Local changeset: 9a1f913b6551
Comment 4 Quality Engineering 2008-09-10 17:21:10 UTC
Integrated into 'main-golden', will be available in build *200809101401* on (upload may still be in progress)
User: Vita Stejskal <>
Log: #144296: applying emi's patch for 'Code folding GUI is broken for the last collapsed folds with innerlevel >0'