aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2021-12-28 14:32:39 +0100
committerFrancesco Abbate <francesco.bbt@gmail.com>2021-12-28 14:36:21 +0100
commit05b003eeb523816f4e87991f0fd06be8d1353d1b (patch)
tree0290d79df22e9a2941b530bca2c9c9aef02a9615
parent0f1b84040dd823823c17e925e1ed10380b7737c1 (diff)
downloadlite-xl-05b003eeb523816f4e87991f0fd06be8d1353d1b.tar.gz
lite-xl-05b003eeb523816f4e87991f0fd06be8d1353d1b.zip
Avoid references to project's dir in TreeView
It is not a good practice to keep a reference to the project's directory object outside of the "core" module itself. The TreeView was using such a reference in the cache item for each file or directory entry. Replace the reference to the object with the absolute name of the project directory.
-rw-r--r--data/core/init.lua9
-rw-r--r--data/plugins/treeview.lua9
2 files changed, 14 insertions, 4 deletions
diff --git a/data/core/init.lua b/data/core/init.lua
index 60c80ec1..aac9a1b2 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -371,6 +371,15 @@ function core.add_project_directory(path)
end
+function core.project_dir_by_name(name)
+ for i = 1, #core.project_directories do
+ if core.project_directories[i].name == name then
+ return core.project_directories[i]
+ end
+ end
+end
+
+
function core.update_project_subdir(dir, filename, expanded)
local index, n, file = project_subdir_bounds(dir, filename)
if index then
diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua
index 2909768c..ffe93ca5 100644
--- a/data/plugins/treeview.lua
+++ b/data/plugins/treeview.lua
@@ -92,7 +92,7 @@ function TreeView:get_cached(dir, item, dirname)
end
t.name = basename
t.type = item.type
- t.dir = dir -- points to top level "dir" item
+ t.dir_name = dir.name -- points to top level "dir" item
dir_cache[cache_name] = t
end
return t
@@ -231,9 +231,10 @@ function TreeView:on_mouse_pressed(button, x, y, clicks)
create_directory_in(hovered_item)
else
hovered_item.expanded = not hovered_item.expanded
- if hovered_item.dir.files_limit then
- core.update_project_subdir(hovered_item.dir, hovered_item.filename, hovered_item.expanded)
- core.project_subdir_set_show(hovered_item.dir, hovered_item.filename, hovered_item.expanded)
+ local hovered_dir = core.project_dir_by_name(hovered_item.dir_name)
+ if hovered_dir and hovered_dir.files_limit then
+ core.update_project_subdir(hovered_dir, hovered_item.filename, hovered_item.expanded)
+ core.project_subdir_set_show(hovered_dir, hovered_item.filename, hovered_item.expanded)
end
end
else