Menu

#1799 Expanding folds when merging two collapsed blocks

Bug
closed-fixed
5
2017-03-21
2016-01-04
No

In our Scintilla based editor, we support folding of consecutive comment lines, i.e. lines that only consists of line comments, e.g.:

// line 1
// line 2

This means that two separate blocks can be merged by either deleting the separating line or by making the separating line a line comment as well:

// line 1 of block 1
// line 2 of block 1

// line 1 of block 2
// line 2 of block 2

If the two blocks are collapsed, Scintilla by default doesn't handle the merging correctly regarding the fold state: the two blocks need to be expanded. The attached patch implements this behaviour in Editor::FoldChanged().

1 Attachments

Related

Bugs: #1833
Bugs: #1896

Discussion

  • Neil Hodgson

    Neil Hodgson - 2016-01-09

    Starting with this C document:

    a {
    b
    }
    c {
    d
    }
    

    where structure 'a' is collapsed, the patch will expand 'a' when the '{' after 'c' is removed.

     
    • Markus Nißl

      Markus Nißl - 2016-01-13

      The attached patch fixes this. The previous block may only be expanded if the fold levels are the same.

       
      • Neil Hodgson

        Neil Hodgson - 2016-01-16

        Its the second hunk in the patch that triggers for the "adding characters in the line" case such as when using Perl in SciTE with fold.compact=0 and this document when a '#' is added to line 3:

        ##
        ##
        
        ##
        ##
        

        Is there an example that triggers the FoldLine in hunk 1?

        Are there any circumstyances in which FoldLines in the patch should collapse? If not then SC_FOLDACTION_EXPAND should be used instead of SC_FOLDACTION_TOGGLE.

        Scintilla must still build with with C++03 so auto for declarations is not possible.

         
        • Markus Nißl

          Markus Nißl - 2016-01-16

          My bad: I mixed up the two comments.

          The new patch fixes the comments and states the cases more precisely. I added one more comment that handles the case "Combining two blocks where the second one is collapsed". I also replaced the auto keyword with the data types.

          Yes, the folds should always expand, never collapse.

          BTW: what's the difference between Editor::FoldLine(line, SC_FOLDACTION_EXPAND) and Editor::FoldExpand(line, SC_FOLDACTION_EXPAND, level)?

           
  • Neil Hodgson

    Neil Hodgson - 2016-01-22

    I haven't found a case where this breaks but I suspect this line needs to mask the levels with SC_FOLDLEVELNUMBERMASK:

        if (prevLineLevel == levelNow && !cs.GetVisible(prevLine))
    

    may change to

        if (((prevLineLevel & SC_FOLDLEVELNUMBERMASK) == 
                  (levelNow & SC_FOLDLEVELNUMBERMASK)) &&
               !cs.GetVisible(prevLine))
    
     

    Last edit: Neil Hodgson 2016-01-22
    • Markus Nißl

      Markus Nißl - 2016-01-25

      Yes, your suggestion will be safer as from a logical point of view, we only want to compare the depth of folding, not taking into account any additional flags.

       
  • Neil Hodgson

    Neil Hodgson - 2016-01-31
    • labels: --> folding
    • status: open --> open-fixed
    • assigned_to: Neil Hodgson
     
  • Neil Hodgson

    Neil Hodgson - 2016-01-31

    Fix committed as [def6d8]. SciTE version in [21ad2b].

     

    Related

    Commit: [21ad2b]
    Commit: [def6d8]

  • Neil Hodgson

    Neil Hodgson - 2016-03-16
    • status: open-fixed --> closed-fixed
     
  • Neil Hodgson

    Neil Hodgson - 2017-01-07

    There are problems with this change mentioned in [#1896]. Making this change more selective may avoid it failing as described.

     

    Related

    Bugs: #1896

  • Neil Hodgson

    Neil Hodgson - 2017-01-07
    • labels: folding --> folding, scintilla
    • status: closed-fixed --> open
     
  • Neil Hodgson

    Neil Hodgson - 2017-03-21
    • status: open --> closed-fixed
     

Log in to post a comment.

MongoDB Logo MongoDB