diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index 8615343..5c2af3c 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -222,7 +222,14 @@ function TreeView:on_mouse_pressed(button, x, y, clicks) else if core.project_files_limit and not hovered_item.expanded then local filename, abs_filename = hovered_item.filename, hovered_item.abs_filename - local index = string.find(abs_filename, filename, 1, true) + local index = 0 + -- The loop below is used to find the first match starting from the end + -- in case there are multiple matches. + while index and index + #filename < #abs_filename do + index = string.find(abs_filename, filename, index + 1, true) + end + -- we assume here index is not nil because the abs_filename must contain the + -- relative filename local dirname = string.sub(abs_filename, 1, index - 2) core.scan_project_folder(dirname, filename) self:invalidate_cache(dirname)