Vasily-X / AutoFoldCode

A Sublime Text package that saves/restores folded code regions in files automatically.
25 stars 5 forks source link

Prevents focus on new files #18

Open dwhenson opened 2 years ago

dwhenson commented 2 years ago

When I create a new file (using file manager package) the package prevents focus remaining on the new file itself and I have to click back to refocus the cursor on the page. I tried removing quite a few plugins before identifying this one as the cause

Unknow0059 commented 2 months ago

Yes. I independently confirmed this before ever arriving here. It was impeding AdvancedNewFile's new files from being focused on.

Unknow0059 commented 2 months ago

This is related to AutoFoldCode (AFC)'s saving and restoring of selections into and from settings.


Regarding saving,

selections are saved on close: https://github.com/Vasily-X/AutoFoldCode/blob/47d1a7e64f560a5b3b3abb79ceb7912bf2605cab/AutoFoldCode.py#L175-L178 ... even zero-width empty selections with a hash of 0x0.

It also seems ST's save_settings() autosaves to a User version of the settings.

This doesn't cause the issue, but it's useless.

Regarding restoring,

Due to on_load_async(), L116's codeblock runs when a new file is made: https://github.com/Vasily-X/AutoFoldCode/blob/47d1a7e64f560a5b3b3abb79ceb7912bf2605cab/AutoFoldCode.py#L134-L137

We see that L137 clears the current selection.

By Default, AFC.sublime-settings' selections value is empty, so L139 adds nothing.

It seems __storage_file__ is loaded from, which ST does not autoresolve to User (nor should it).

Meanwhile, __storage_path__ is a variable that exists and points to User settings, and is not used anywhere.

Problem

Workarounds: