Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#703 keep code-folding when automatic text changes happen

v1.23
open
nobody
5
2014-09-03
2014-01-13
Freddi
No

When using search&replace over the whole document, all folded sections can become expanded again if text is changed in them. Similarly, all folded sections expand when indenting or undenting a large portion of the document. This can be annying because it increases the visible complexity of the source code.

Would it make sense to expand folded sections only when the user clicks the [+] button or when a text change is directly done by the user?

Discussion

  • Lex Trotman
    Lex Trotman
    2014-01-13

    Changing the buffer contents may change fold points, possibly removing or moving existing fold points or adding new ones. It is quite complex to decide what to do in the face of changes to the fold points. The only fold condition that is always safe is fully unfolded, so where changes are made, the folds are unfolded. So if your whole file replace changes enough it will unfold the whole file.

    Again indent/undent is a change to the buffer and may change fold points (think Python for example).

    A secondary benefit of unfolding is to make all changes visible, having changes hidden from you is potentially dangerous.

     
  • Freddi
    Freddi
    2014-01-20

    A similar issue is when creating a multi-line comment:

    A
    B
    C
    D {
      d1
      d2
    }
    

    Step 1: collapse D

    A
    B
    C
    [+]D {
    

    Step 2: start a multi-line comment to comment out BC

    A
    /*B
    C
    [+]D {
    

    Step 3: end the multi-line comment

    A
    /*B
    C*/
    [+]D {
    

    Expected result: code outside of the edited sections is not affected.
    Observed result: With step 2, all collapsed/folded code sections below get expanded (and formatted as multi-line comment):

    A
    /*B
    C
    D {
      d1
      d2
    }
    

    I understand that from how the syntax-highlighting and code-folding works, it temporarily interpretes the rest of the file as belonging inside the comment. After closing the comment, it currently cannot recognize which code sections correspond to previously folded sections. Is there not a chance to improve this usability issue?

     
    • Lex Trotman
      Lex Trotman
      2014-01-20

      This behaviour is correct. At step 2 the {} block at D is no longer a block that can be folded, its part of the comment starting at B, so the fold is removed and the text unfolded.