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