Menu

#2220 Buggy collapsing in PHP containing HTML in-between

Bug
closed-invalid
5
2021-06-02
2020-10-25
No

If there is HTML between 2 PHP zones and a control structure like if, switch, for etc is going through these zones then on collapsing the control structure in first zone is collapsing contents in the first zone only instead of collapsing up to its end bracket.

Steps to Reproduce the Issue

  • Write following in a PHP file (attached first screenshot):
<?php
if(1) {
    // some php code
?>
    <p>some html</p>
<?php
    // some php code
}
  • Collapse/fold the if line (line # 2)
  • The content up to the 4th line (inclusive) (only that PHP zone) is collapsing

Expected Behavior

It should collapse to the ending bracket of if and show as following:

<?php
if(1) {

Actual Behavior (attached 2nd screenshot)

<?php
if(1) {
    <p>some html</p>
<?php
    // some php code
}

I have reported this bug in Notepad++ at here: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/9054

Screenshot 1
Screenshot 1

Screenshot 2
Screenshot 2

Related

Bugs: #2291

Discussion

  • Neil Hodgson

    Neil Hodgson - 2020-10-25
    • status: open --> open-invalid
    • assigned_to: Neil Hodgson
     
  • Neil Hodgson

    Neil Hodgson - 2020-10-25

    This is behaving as designed. The primary approach to folding in Scintilla recognizes strictly nested fold structures. Each start or end fold point increments or decrements a 'fold level'. There is no concept of compatibility between start and end fold points. So, the "{" increments the fold level and the "?>" decrements the fold level creating a foldable section.

    It may be possible to implement a folding system that matches up only compatible points: "{" with "}" and "<?php" with "?>". I do not know how to do this but you could try to work on it using the SCI_SHOWLINES and SCI_HIDELINES calls directly rather than through the normal folding mechanism.

    Since this is behaving as designed it is not considered a bug and this issue is marked "invalid".

     
  • Nikunj Bhatt

    Nikunj Bhatt - 2020-10-25

    I understood how it has been implemented but as I don't know C++ language, I can't understand and try:

    work on it using the SCI_SHOWLINES and SCI_HIDELINES calls directly rather than through the normal folding mechanism

    However, from a programmer's perspective I have suggestion which may help you to enhance the fold system. Instead of just incrementing/decrementing "fold level", you may create a list/array containing 2 elements of arrays which stores/saves the starting point (line) and ending point of the folds for each fold structures. With this method, the fold structures may overlap each other.

     
    • Neil Hodgson

      Neil Hodgson - 2020-10-27

      Instead of just incrementing/decrementing "fold level", you may ... stores/saves the starting point (line) and ending point of the folds

      Now you have to match starting and ending points in a generic way and handle different failure scenarios where folding features do not match. There would also have to be work on the generic folding mechanism to understand this data and define a meaning for operations like "fold all". This change would have to be compatible with over a hundred existing folders. It may be possible but it is not trivial.

       
  • Nikunj Bhatt

    Nikunj Bhatt - 2020-12-03

    If current implementation is considered in regard to the following code example:
    Screenshot 1

    ... then only the 3 to 5 lines should get hidden as following (edited screenshot):
    Screenshot 2

    ... but what actually happening is:
    Screenshot 3

    ... and this last one is correct, logical.

    So, the point is the - collapsing behaviour is different than the matching of bracket pairs in case of "HTML between 2 PHP zones".

     
    • Colomban Wendling

      No, the current implementation allows nested folds fine, it just only supports one single "type" of fold points. In your example, lines1 and 9 have a fold depth of 1, 2-3 and 7-8 a depth of 2, and 4-6 a depth of 3. As Neil said, it's basically depth+1 when starting a fold, and depth-1 when ending it.

      What you are looking for is not really possible conceptually to me so long as <?php … ?> sections do fold (and that's actually only an example, I can think of other problematic cases): you would need to fold a section that spans past an upper level of folding.
      There might be UIs better suited to that than the ones I know, but with the one Scintilla has I don't see a non-confusing way to achieve this (regardless of how it's internally done).

      Actually, what your OP sample has is (conceptually):
      a fold spanning lines 1-4 (the first PHP section)
      a fold spanning lines 2-8 (the if)
      * a fold spanning lines 6-9 (the second PHP section)

      What should happen when folding the first one? It contains the start of the second fold section, so should it fold it as well? But it doesn't contain the end of that second fold, so there's no reason to fold it. It's almost worse for the 3rd fold that starts in the middle of the second: what to do if you fold the second, should it fold the third, although its end is definitely not included?

      In the end, what makes the most sense to me here would be disabling folding for HTML in this kind of files, or decide one kind of fold "takes over". I guess in the OP example, if could make sense to never fold lines 1-4 or 6-9 alone, and fold lines 2-8 instead (we'd then have only 2 folds: one over lines 1-9, and one over lines 2-8).
      This could be implemented with the current system, it's a "mere" matter of the PHP folder to not place fold start/ends on PHP tags if inside a bracket pair (which is non-trivial to do I think, but totally possible).

       
      👍
      1
      • Nikunj Bhatt

        Nikunj Bhatt - 2021-01-06

        I understood the problem.

        I think that all 3 sections should be collapsible: 1-9, 2-8 and 6-9. I know it is overlapping.

        If it isn't possible then let it work the way it is. There is "hide lines" feature in Notepad++ (I don't know whether this feature of Notepad++ or Scintilla) which can be used to hide lines in any manner; so, this extra mechanism can be avoided.

         
        • Neil Hodgson

          Neil Hodgson - 2021-01-06

          The "hide lines" feature is specific to Notepad++.

           
          👍
          1
  • Neil Hodgson

    Neil Hodgson - 2021-06-02
    • status: open-invalid --> closed-invalid
     

Log in to post a comment.