vim icon indicating copy to clipboard operation
vim copied to clipboard

Marker folds gets corrupted when certain text gets cut/deleted and an undo for that it occurs

Open yousef8192 opened this issue 1 year ago • 3 comments
trafficstars

Steps to reproduce

This issue is related to #15455 and consists of two cases. To reproduce do as follows :

  1. enter vim using vim --clean -c ':set fdm=marker'
  2. insert the following text then follow what's being mentioned below.
{{{ Parent Fold 1

}}}



{{{ Parent Fold 2



{{{ Nested Fold A



{{{ Double Nested Fold A1

}}}



{{{ Double Nested Fold A2

}}}



{{{ Double Nested Fold A3

}}}



}}}



{{{ Nested Fold B








































}}}



{{{ Nested Fold C

{{{ Double Nested Fold C1

}}}

{{{ Double Nested Fold C2

}}}

{{{ Double Nested Fold C3

}}}

}}}



}}}



{{{ Parent Fold 3

}}}



{{{ Parent Fold 4





}}}



  • [Case 1] cutting/deleting the line just before the start of any fold (whether itself is nested or not) that contains nested folds (such as the lines 6,10,81 but not 36,103) then undoing with u (or <esc>u for insert mode) :

    • in visual line mode : fold corruption MAY occur
    • in visual mode : fold corruption MAY occur
    • using dd : no fold corruption
    • in insert mode using one or more <bs> : no fold corruption
    • in insert mode using one or more <delete> : fold corruption occurs
  • Notes regarding this case :

    • When cutting/deleting in visual line mode, corruption occurs only if the line just before the start of the fold is the last line in the selection and the number of lines in the selection is MORE THAN the number of lines inside the fold (execluding the lines that mark the start/end of the fold), for an instance consider cutting/deleting the following lines then undoing :

      • For "Parent Fold 3" (contains one line only inside it which is line 105)

        1. line 103 : no corruption occurs (because number of lines in the selection is equal to number of lines inside the fold)
        2. lines 101 to 104 : no corruption occurs (because the line just before the start of the fold isn't the last line in the selection)
        3. lines 102 to 103 : corruption occurs (because number of lines in the selection is more than number of lines inside the fold)
        4. lines 1 to 103 : corruption occurs (because number of lines in the selection is more than number of lines inside the fold)
      • For "Parent Fold 4" (contains five line inside it which are lines 111 to 115)

        1. line 109 : no corruption occurs (because number of lines in the selection is equal to number of lines inside the fold)
        2. lines 103 to 110 : no corruption occurs (because the line just before the start of the fold isn't the last line in the selection)
        3. lines 103 to 109 : corruption occurs (because number of lines in the selection is more than number of lines inside the fold)
        4. lines 1 to 109 : corruption occurs (because number of lines in the selection is more than number of lines inside the fold)
    • When cutting/deleting in visual mode, corruption occurs only if the line just before the start of the fold is the last line in the selection and the selection doesn't contain any of the above folds or part of them. For an instance suppose cutting/deleting the following lines in visual mode then undoing :

      1. line 4 to 6 : no corruption occurs because line 6 isn't the last line in the selection
      2. line 6 to 7 : no corruption occurs because line 6 isn't the last line in the selection
      3. line 1 to 6 : no corruption occurs because the selection contains "Parent Fold 1"
      4. line 3 to 6 : no corruption occurs because the selection contains a part of "Parent Fold 1"
    • When cutting/deleting in visual mode, the number of lines that get corrupted seems to be proportional with the number of lines in the selection (where the selection must satisfy the conditions mentioned above). For an instance suppose cutting/deleting the following lines in visual mode then undoing :

      1. line 6 : last two lines of "Parent Fold 2" get corrupted (i.e. line 99,100)
      2. line 5,6 : last three lines of "Parent Fold 2" get corrupted (i.e. line 98,99,100)
      3. line 4,5,6 : last four lines of "Parent Fold 2" get corrupted (i.e. line 97,98,99,100)
      4. and so on...
    • When cutting/deleting in visual mode, if the number of lines in the selection (where the selection must satisfy the conditions mentioned above) is MORE THAN OR EQUAL TO the number of lines inside the fold (execluding the lines that mark the start/end of the fold), no corruption occurs. For an instance, the number of lines inside "Parent Fold 2" execluding the lines which mark its start/end is 92 (i.e. from line 8 to 99), now notice the following :

      1. Suppose there are 92 or more empty lines between "Parent Fold 1" and "Parent Fold 2", in this case no corruption occurs upon cutting/deleting these lines in visual mode then undoing.
      2. However, if there is 91 or less empty lines then corruption occurs which is proportional to the number of lines in the selection as mentioned above.



  • [Case 2] cutting/deleting the line just before the start of any nested fold (such as the lines 10,14,36,81,83 and others) then undoing with u (or <esc>u for insert mode) :

    • in visual line mode : fold corruption MAY occur
    • in visual mode : fold corruption MAY occur
    • using dd : fold corruption occurs
    • in insert mode using one or more <bs> : fold corruption occurs
    • in insert mode using one or more <delete> : no fold corruption
  • Notes regarding this case :

    • When cutting/deleting in visual mode, the issues that occur are mentioned in the first case.

    • When cutting/deleting in visual line mode, the number of lines that get corrupted seems to be proportional with the number of lines in the selection (same idea as the first case).

    • When cutting/deleting in visual line mode, if the number of lines in the selection is more than or equal to the number of lines inside the fold (execluding the lines that mark the start/end of the fold), no corruption occurs (same idea as the first case).

    • When cutting/deleting in visual line mode, corruption occurs only if the line just before the start of the nested fold is the last line in the selection and some other conditions that I couldn't really grasp (examples with ??? are the ones that I couldn't really understand). For an instance suppose cutting/deleting the following lines in visual line mode then undoing :

      • For "Nested Fold A"

        1. line 8 to 10 : corruption occurs as expected
        2. line 8 to 9 : no corruption occurs (because the line just before the start of the fold isn't the last line in the selection)
        3. line 8 to 11 : no corruption occurs (because the line just before the start of the fold isn't the last line in the selection)
        4. line 7 to 10 : corruption occurs (notice the inclusion of the start of "Parent Fold 2")
        5. line 6 to 10 : corruption occurs (notice the inclusion of the start of "Parent Fold 2")
        6. line 1 to 10 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold A")
        7. line 3 to 10 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold A")
      • For "Nested Fold B"

        1. line 34 to 36 : corruption occurs as expected
        2. line 34 to 35 : no corruption occurs (because the line just before the start of the fold ins't the last line in the selection)
        3. line 34 to 37 : no corruption occurs (because the line just before the start of the fold ins't the last line in the selection)
        4. line 33 to 36 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold B")
        5. line 10 to 36 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold B")
        6. line 1 to 36 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold B")
      • For "Nested Fold C"

        1. line 79 to 81 : corruption occurs as expected
        2. line 79 to 80 : no corruption occurs (because the line just before the start of the fold ins't the last line in the selection)
        3. line 79 to 82 : no corruption occurs (because the line just before the start of the fold ins't the last line in the selection)
        4. line 78 to 81 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold C")
        5. line 75 to 81 : ??? no corruption occurs (despite number of lines in the selection is less than that's inside "Nested Fold C")
        6. line 38 to 81 : ??? no corruption occurs (notice start of the selection is the line just after the start line of "Nested Fold B")
        7. line 37 to 81 : ??? corruption occurs (notice start of the selection is the start line of "Nested Fold B")
        8. line 35 to 81 : ??? corruption occurs (notice start of the selection is an empty line between "Nested Fold A" and "Nested Fold B")
        9. line 33 to 81 : ??? no corruption occurs (notice start of the selection is a line which is part of "Nested Fold A")
        10. line 22 to 81 : ??? no corruption occurs (notice start of the selection is a line which is part of "Nested Fold A")
        11. line 11 to 81 : ??? corruption occurs (notice start of the selection is the start line of "Nested Fold A")
        12. line 9 to 81 : ??? corruption occurs (notice start of the selection is an empty line between start of "Parent Fold 2" and "Nested Fold A")
        13. line 7 to 81 : ??? no corruption occurs (notice start of the selection is the start line of "Parent Fold 2")
        14. line 1 to 81 : ??? no corruption occurs

Expected behaviour

No fold corruption occurs when trying the mentioned examples above.

Really sorry if this issue is bloated, I tried to explain as much as possible. If there are further information needed that I didn't provide please let me know. Thanks a lot in advance for your time and help!

Version of Vim

version: 9.1, patch level: 1-672

Environment

Operating system: Linux Terminal: Terminator Value of $TERM: screen-256color Shell: Bash

Logs and stack traces

No response

yousef8192 avatar Aug 12 '24 20:08 yousef8192

can you please give a reproducible example using vim commands when this occurs?

chrisbra avatar Aug 12 '24 20:08 chrisbra

Of course, I am really sorry that the issue is bloated, I hope the observations written in it are somewhat helpful.

:102|norm! zRVjxu :1|norm! zRV102jxu :103|norm! zRV6jxu :1|norm! zRV108jxu :6|norm! zRvxu :5|norm! zRvjxu :4|norm! zRv2jxu :8|norm! zRV2jxu :7|norm! zRV3jxu :6|norm! zRV4jxu :34|norm! zRV2jxu :79|norm! zRV2jxu :37|norm! zRV44jxu :35|norm! zRV46jxu :11|norm! zRV70jxu :9|norm! zRV72jxu

yousef8192 avatar Aug 12 '24 21:08 yousef8192

Some more commands :

:10| norm! zRddu :14| norm! zRddu :36| norm! zRddu :7|call feedkeys("i<bs><esc>u") :11|call feedkeys("i<bs><esc>u") :37|call feedkeys("i<bs><esc>u") :82|call feedkeys("i<bs><esc>u") :6|call feedkeys("i<del><esc>u") :10|call feedkeys("i<del><esc>u") :36|call feedkeys("i<del><esc>u") :81|call feedkeys("i<del><esc>u")

yousef8192 avatar Aug 13 '24 15:08 yousef8192