Interesting list folding behavior

Hello, I am the author of a Markdown app called MarkEdit, recently I was asked an interesting question about the list folding behavior, source: Fold sublist of first bullet if present rather than first bullet’s entire list · Issue #493 · MarkEdit-app/MarkEdit (github.com).

(#1) * Item 1
    - Subitem 1
    - Subitem 2
* Item 2
(#2) * Item 3
    - Subitem 1
    - Subitem 2
    - Subitem 3
* Item 4

So, the inconsistency is that when we click on #1, it folds the entire list, but when we click on #2, it only folds the sub-list of Item 3 (the issue ticket has some screenshots to better understand).

This is quite interesting, and I don’t have a good explanation for this, do you have an idea?

This can be reproduced with the official demo: Try CodeMirror.

Thank you!

CodeMirror’s folding works per-line—it associates a foldable range with a line. For syntax tree based folding, that range is the outermost foldable node that starts in the line. So at line 1, both the whole list and the first list item start in that line, and the list is the bigger of the two.

VS Code seems to only fold list items, not lists, possibly for this very reason. I can imagine it being useful to fold an entire list in some situations, but maybe the added consistency of that behavior would be an improvement. What do you think?

Yeah I just tried VS Code, like you said it only folds sub-items. IMHO, consistency is more important, the current behavior is a bit confusing if we don’t know the rationale.

Okay, let’s go with that. Though note that a similar issue exists for all nested markup—you cannot fold the first paragraph of a list item, since the item fold takes precedence, or the first list item in a blockquote, and so on. I don’t think following VS Code and making only list items foldable is the way to go for that (and even that still has the problem on nested list items).

Thank you marijn!