Author Topic: Reproducible Folding Bug  (Read 8766 times)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9621
Reproducible Folding Bug
« on: March 05, 2007, 08:01:17 am »
Dear folks,
this is to remember that there is still a folding bug in C::B. It may be addressed by a patch already... if so: Which one?! If not, then this is a reminder on what to do. ;-)
Look here: http://savefile.com/files/533241
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #1 on: March 06, 2007, 03:36:00 pm »
Edit 1: Removed wrong patch. Will update if the bug gets fixed.

Sorry for this. :)
« Last Edit: March 06, 2007, 03:47:59 pm by Biplab »
Be a part of the solution, not a part of the problem.

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Reproducible Folding Bug
« Reply #2 on: March 07, 2007, 08:55:06 am »
I can't reproduce at all...

BTW, if someone is willing to apply some patches on fold bugs, here's one: http://developer.berlios.de/patch/?func=detailpatch&patch_id=1740&group_id=5358

I tested it for about two months and all works fine. Maybe it's the fix to this bug...

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9621
Re: Reproducible Folding Bug
« Reply #3 on: March 07, 2007, 09:55:30 am »
I can't reproduce at all...
What does that mean? They are not reproducible on the SVN version for you or at the SVN+BerliOS patch #1740 version your are using? (Maybe I should apply the patch myself to see...)
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #4 on: March 07, 2007, 10:40:19 am »
I can't reproduce at all...

I can reproduce it.

What does that mean? They are not reproducible on the SVN version for you or at the SVN+BerliOS patch #1740 version your are using? (Maybe I should apply the patch myself to see...)
With regards, Morten.

I believe you don't need to test it. I've already tested it and found it basically sets the behavior to Unfold Current Fold which is, I believe, not the way we want it to work.

I'm currently working on it and Fold/Unfold current block now works perfectly. I'm facing some issues with Toggle current block. If you wish, I can post the patch. :)

Regards,

Biplab
Be a part of the solution, not a part of the problem.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #5 on: March 07, 2007, 12:31:23 pm »
I hope this time I'm posting the right fix. I've demonstrated in the demo movie that it works well. :)

Download the movie from:
Quote
http://www.fileden.com/files/4628/wxScintillaFix.7z

Patch:
Code
Index: sdk/cbeditor.cpp
===================================================================
--- sdk/cbeditor.cpp (revision 3669)
+++ sdk/cbeditor.cpp (working copy)
@@ -1485,12 +1485,43 @@
 void cbEditor::DoFoldBlockFromLine(int line, int fold)
 {
     m_pControl->Colourise(0, -1); // the *most* important part!
-    int i = line;
+    /*int i = line;
     while (i != 0)
     {
         if (DoFoldLine(i, fold))
             return;
         --i;
+    }*/
+    int i, level;
+    int maxLine = m_pControl->GetLastChild(line, -1);
+    bool expand = (fold == 0 ? true : false);
+    bool IsCurLineFolded; /* Is current line folded? */
+
+    if (maxLine >= line)
+    {
+        /* The following code may be replaced with DoFoldLine(line, fold)
+        *  call. But I found that doesn't solve Unfold Current Block problem.
+        *  In my opnion,  ShowLines(lineFrom, lineTo) and
+        *  HideLines(lineFrom, lineTo) calls are not working properly.
+        *
+        *  Need More detailed investigation - [Biplab]
+        */
+        for (i = line; i <= maxLine; ++i)
+        {
+            level = m_pControl->GetFoldLevel(i);
+            IsCurLineFolded = m_pControl->GetFoldExpanded(i);
+            if (level & wxSCI_FOLDLEVELHEADERFLAG)
+            {
+                if (fold == 2) // We want to toggle current block.
+                    m_pControl->ToggleFold(i); //But strangely it doesn't toggle root
+                /* fold = 0 (Unfold), 1 (fold), 2 (toggle)
+                *  So check if fold = 0 then GetFoldExpanded(line) = false
+                *  before toggling it and vice-versa
+                */
+                else if ((!IsCurLineFolded && expand) || (IsCurLineFolded && !expand))
+                    m_pControl->ToggleFold(i);
+            }
+        }
     }
 }

Known Issue:
This patch fails to solve One Issue. If Toggle current block is selected, it fails to toggle the root, from where it's called, if any child is in folded state inside. Though it changes the fold state of all childs successfully.

Regards,

Biplab
« Last Edit: March 07, 2007, 12:33:43 pm by Biplab »
Be a part of the solution, not a part of the problem.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #6 on: March 07, 2007, 03:30:53 pm »
@Morten

Bug fixed finally. Known issue reported in last reply has also been fixed. Committed in revision 3671. :)

I've modified DoFoldLine() SDK function.

I'm not posting the patch.

Regards,

Biplab
Be a part of the solution, not a part of the problem.

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9621
Re: Reproducible Folding Bug
« Reply #7 on: March 07, 2007, 07:07:56 pm »
Bug fixed finally. Known issue reported in last reply has also been fixed. Committed in revision 3671. :)
Nice one!!! :D I'm currently compiling C::B to give it a try. GREAT work though!
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #8 on: March 07, 2007, 07:13:34 pm »
But this changes have made a minor change in SDK. It fails in cases where child is inside a parent and folded. Will try to update it.
« Last Edit: March 07, 2007, 08:01:10 pm by Biplab »
Be a part of the solution, not a part of the problem.

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Reproducible Folding Bug
« Reply #9 on: March 07, 2007, 10:35:09 pm »
I can't reproduce at all...
What does that mean? They are not reproducible on the SVN version for you or at the SVN+BerliOS patch #1740 version your are using?
I don't see another meaning:
http://savefile.com/files/536851

On "rev 3669 - gcc 3.4.5 Windows/unicode"


Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #10 on: March 08, 2007, 06:04:05 am »
Ok, I'm posting a video showing the bug in Rev 3669 Nightly.
Quote
http://www.fileden.com/files/4628/wxScintilla_CB_Rev3669.7z

See the video after the fix have been applied in Rev 3672 Nightly.
Quote
http://www.fileden.com/files/4628/wxScintilla_CB_Rev3672.7z

You can easily find out the difference. :)

Regards,

Biplab
Be a part of the solution, not a part of the problem.

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Reproducible Folding Bug
« Reply #11 on: March 08, 2007, 12:36:40 pm »
I do see the difference. I suggest to test the patch i posted before, because i don't have that bug in rev 3669. "My" patch was supposed to fix the unfold bug when an error line is highlighted (that is, only the block where the fold is was unfolded), and since both patches modify the same function, i'll surely get conflicts on update.

EDIT: http://forums.codeblocks.org/index.php/topic,5360.msg41649.html#msg41649
« Last Edit: March 08, 2007, 12:41:19 pm by kkez »

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #12 on: March 08, 2007, 02:46:36 pm »
Bug fixed finally. Known issue reported in last reply has also been fixed. Committed in revision 3671. :)

I've modified DoFoldLine() SDK function.

I'm not posting the patch.
For your information, the patch I posted in the last thread to quote is different from the patch I've applied in repository. That was the reason I've mentioned that I'm not posting the patch. You may see the diff at the following link.

Quote
http://svn.berlios.de/viewcvs/codeblocks?view=rev&rev=3671

I did test your patch. But I couldn't accept it as it works differently than what it is supposed to do. I'm posting your patch in pieces and showing you why it was not accepted.

Code
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 3455)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -1467,13 +1467,37 @@
 
 void cbEditor::DoFoldBlockFromLine(int line, int fold)
 {
-    m_pControl->Colourise(0, -1); // the *most* important part!
+    /*m_pControl->Colourise(0, -1); // the *most* important part!
     int i = line;
     while (i != 0)
     {
         if (DoFoldLine(i, fold))
             return;
         --i;
+    }*/
+   
+    ConfigManager* mgr = Manager::Get()->GetConfigManager(_T("editor"));
+    if (mgr->ReadBool(_T("/folding/show_folds"), true)) //Only unfold the marked line if the folds are enabled ... duh
+    {
+        m_pControl->Colourise(0, -1); // the *most* important part!
+        int level = m_pControl->GetFoldLevel(line);
+        int parent = m_pControl->GetFoldParent(line);
+       
+        //Check for fold headers
+        if ((level & wxSCI_FOLDLEVELHEADERFLAG) && (wxSCI_FOLDLEVELBASE <= (level & wxSCI_FOLDLEVELNUMBERMASK)))
+           parent = line;
+        if (parent != -1)
+        {
+            if (m_pControl->GetFoldExpanded(parent) == false && fold == 0)
+                m_pControl->ToggleFold(parent);
+            else
+            {
+                if (m_pControl->GetFoldExpanded(parent) == true && fold == 1)
+                    m_pControl->ToggleFold(parent);
+                else if (fold == 2)
+                    m_pControl->ToggleFold(parent);
+            }
+        }
     }
 }

The patch removed the recursive search to find it's parents and thus it was in conflict with what the function supposed to do. It works well for one level but not for multiple levels.

"My" patch was supposed to fix the unfold bug when an error line is highlighted (that is, only the block where the fold is was unfolded), and since both patches modify the same function, i'll surely get conflicts on update.

I'm working on fixing this issue. The code is ready and currently I'm testing it. Hopefully you'll get the fix in next nightly.

As a different patch was applied earlier, second part of your patch to fix this had to be reworked. I've reworked this to avoid any change in SDK. :)

I couldn't understand the last part (why it's needed) and thus I'm keeping it on hold.

Thanks for your hard work in providing a solution. :)

Regards,

Biplab
Be a part of the solution, not a part of the problem.

Offline Biplab

  • Developer
  • Lives here!
  • *****
  • Posts: 1874
    • Biplab's Blog
Re: Reproducible Folding Bug
« Reply #13 on: March 08, 2007, 04:39:49 pm »
Unfolding of code when an error/warning line is selected/highlighted fix is in revision 3674. :)

Regards,

Biplab
Be a part of the solution, not a part of the problem.

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Reproducible Folding Bug
« Reply #14 on: March 08, 2007, 10:02:10 pm »
Well,

Quote
I did test your patch. But I couldn't accept it as it works differently than what it is supposed to do. I'm posting your patch in pieces and showing you why it was not accepted.
...
The patch removed the recursive search to find it's parents and thus it was in conflict with what the function [was] supposed to do. It works well for one level but not for multiple levels.
Are you sure?

Quote
why it's needed
I don't understand this question, don't you see the bug?

Btw, i mistyped when i explained the bug: only the block where the error line is is unfolded.

Quote
Thanks for your hard work in providing a solution.
If this isn't sarcastic, i'll say that the patch is not mine (that's why i surrounded "my" with quotation marks)

Quote
Unfolding of code when an error/warning line is selected/highlighted fix is in revision 3674
Thank you, i'll test it asap.