From 9e7bdf49e9b4b5e38bc2a95d7e7aa6b607c86468 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 22 Dec 2021 23:39:26 +0100 Subject: [PATCH 1/3] Revert "Merge pull request #697 from Guldoman/treeview_remove_changed" This reverts commit 4e078cc2171f1c01150b09db7d091a2dfdbf715a, reversing changes made to 0c488c94920a1100986fa73e11ccc4a2c5cd5667. --- data/core/init.lua | 2 +- data/plugins/treeview.lua | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index bb3647ec..a85b5d0d 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1158,7 +1158,7 @@ end -- no-op but can be overrided by plugins -function core.on_dirmonitor_modify(dir, filepath) +function core.on_dirmonitor_modify() end diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index f7c7f5ba..b6de33b2 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -45,14 +45,6 @@ function TreeView:new() self.item_icon_width = 0 self.item_text_spacing = 0 - - local on_dirmonitor_modify = core.on_dirmonitor_modify - function core.on_dirmonitor_modify(dir, filepath) - if self.cache[dir.name] then - self.cache[dir.name][filepath] = nil - end - on_dirmonitor_modify(dir, filepath) - end end From 9155be7a2268548bb488d6e294dd2ee043453c28 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Mon, 20 Dec 2021 11:03:49 +0100 Subject: [PATCH 2/3] Ensure TreeView cache entry is removed on delete Address issue: https://github.com/lite-xl/lite-xl/issues/689 Attempt to provide a more accurate fix to commit: 59f64088e1e88f2f2a29e4d5418ccdf781fdc12e For this latter what happens is that any change inside a directory cause the corresponding entry to be folded in the TreeView. The new change is more accurate because we remove only the stale entry corresponding to the delete event and we do not reset the cache of the parent directory using the modify event. --- data/core/init.lua | 5 +++-- data/plugins/treeview.lua | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index a85b5d0d..0b4c355f 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1158,8 +1158,8 @@ end -- no-op but can be overrided by plugins -function core.on_dirmonitor_modify() -end +function core.on_dirmonitor_modify() end +function core.on_dirmonitor_delete() end function core.on_dir_change(watch_id, action, filepath) @@ -1168,6 +1168,7 @@ function core.on_dir_change(watch_id, action, filepath) core.dir_rescan_add_job(dir, filepath) if action == "delete" then project_scan_remove_file(dir, filepath) + core.on_dirmonitor_delete(dir, filepath) elseif action == "create" then project_scan_add_file(dir, filepath) core.on_dirmonitor_modify(dir, filepath); diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index b6de33b2..4d1207f2 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -45,6 +45,19 @@ function TreeView:new() self.item_icon_width = 0 self.item_text_spacing = 0 + self:add_core_hooks() +end + + +function TreeView:add_core_hooks() + -- When a file or directory is deleted we delete the corresponding cache entry + -- because if the entry is recreated we may use wrong information from cache. + local on_delete = core.on_dirmonitor_delete + core.on_dirmonitor_delete = function(dir, filepath) + local cache = self.cache[dir.name] + if cache then cache[filepath] = nil end + on_delete(dir, filepath) + end end From eac82e69fb1016fb351349be919539989425d530 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Wed, 22 Dec 2021 23:43:56 +0100 Subject: [PATCH 3/3] Add parameters to `core.on_dirmonitor_{modify,delete}` --- data/core/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 0b4c355f..c76c6366 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1158,8 +1158,8 @@ end -- no-op but can be overrided by plugins -function core.on_dirmonitor_modify() end -function core.on_dirmonitor_delete() end +function core.on_dirmonitor_modify(dir, filepath) end +function core.on_dirmonitor_delete(dir, filepath) end function core.on_dir_change(watch_id, action, filepath)