diff options
| author | Francesco Abbate <francesco.bbt@gmail.com> | 2022-01-06 18:00:15 +0100 |
|---|---|---|
| committer | Francesco Abbate <francesco.bbt@gmail.com> | 2022-01-06 18:00:48 +0100 |
| commit | 7ded5c819929e6e06a9fc21cd964ebbfb22542d1 (patch) | |
| tree | 75008f5c88267431313d9cf8e46f76135e398067 | |
| parent | 1e7075ca9fb59c4f237d747ee7e7fd06baaf183a (diff) | |
| download | lite-xl-7ded5c819929e6e06a9fc21cd964ebbfb22542d1.tar.gz lite-xl-7ded5c819929e6e06a9fc21cd964ebbfb22542d1.zip | |
Fix problem when reloading project directory
| -rw-r--r-- | data/core/init.lua | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/data/core/init.lua b/data/core/init.lua index aba10d8f..52f4112a 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -440,13 +440,27 @@ local function rescan_project_directories() for i = 1, n do -- add again the directories in the project local dir = core.add_project_directory(save_project_dirs[i].name) if dir.files_limit then - for subdir, show in pairs(save_project_dirs[i].shown_subdir) do + -- We need to sort the list of shown subdirectories so that higher level + -- directories are populated first. We use the function system.path_compare + -- because it order the entries in the appropriate order. + -- TODO: we may consider storing the table shown_subdir as a sorted table + -- since the beginning. + local subdir_list = {} + for subdir in pairs(save_project_dirs[i].shown_subdir) do + table.insert(subdir_list, subdir) + end + table.sort(subdir_list, function(a, b) return system.path_compare(a, "dir", b, "dir") end) + for _, subdir in ipairs(subdir_list) do + local show = save_project_dirs[i].shown_subdir[subdir] for j = 1, #dir.files do if dir.files[j].filename == subdir then -- The instructions below match when happens in TreeView:on_mouse_pressed. -- We perform the operations only once iff the subdir is in dir.files. - core.update_project_subdir(dir, subdir, show) + -- In theory set_show below may fail and return false but is it is listed + -- there it means it succeeded before so we are optimistically assume it + -- will not fail for the sake of simplicity. core.project_subdir_set_show(dir, subdir, show) + core.update_project_subdir(dir, subdir, show) break end end |
