From my memories of investigating the Editor's code, the root of this problem is that the whole subtree is getting recreated each time something changes in it. This is quite inefficient, and of course this causes the folders loose their collapsed/expanded state.
I do not know why this is done so, or since when, but it's possible that this behavior was introduced along with the folder support, which was done by contributors around the time the Editor went opensource (AGS v3.2.2).
The dumb approach would be to fix the consequence of the problem, for instance: remember which folders are expanded and restore them after the change. But the ideal approach would be to fix the root of the problem: find out why this subtree recreation is ever necessary, and change the code so that it's not performed.
EDIT: Opened a ticket:
https://github.com/adventuregamestudio/ags/issues/2105
I do not know why this is done so, or since when, but it's possible that this behavior was introduced along with the folder support, which was done by contributors around the time the Editor went opensource (AGS v3.2.2).
The dumb approach would be to fix the consequence of the problem, for instance: remember which folders are expanded and restore them after the change. But the ideal approach would be to fix the root of the problem: find out why this subtree recreation is ever necessary, and change the code so that it's not performed.
EDIT: Opened a ticket:
https://github.com/adventuregamestudio/ags/issues/2105