As TaskPaper documents are plain text files, folding state can only be stored in extended attributes of a file, or in Apple’s user interface preservation API.
The retention or loss of extended attributes, and the contexts in which each occurs, depends more on operating system design, and on the behaviour of other applications, than on the design of TaskPaper.
As I understand it, TP discards the folding state, if the document has been changed externally.
It’s actually not TaskPaper that discards the state.
The first thing to explore, from the Terminal prompt, might be:
(To read the documentation on the xattr command)
and you can see the storage of folding state by running xattr on a file written out by TaskPaper itself, rather than by some other application or utility.
For example, if I have a TaskPaper-written text file with the path:
then with the -l switch of xattr:
xattr -l ~/Notes/notes2020-01-06.taskpaper
I may see things like:
"collapsedItemIDs": ["1149416613", "712709677", "3819108301", "2365024637"],