diff --git a/data/core/init.lua b/data/core/init.lua
index 7adb316b..e571e6b4 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -195,6 +195,16 @@ local function project_scan_thread()
 end
 
 
+function core.is_project_folder(dirname)
+  for _, dir in ipairs(core.project_directories) do
+    if dir.name == dirname then
+      return true
+    end
+  end
+  return false
+end
+
+
 function core.scan_project_folder(dirname, filename)
   for _, dir in ipairs(core.project_directories) do
     if dir.name == dirname then
diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua
index 5c2af3c4..8214bda4 100644
--- a/data/plugins/treeview.lua
+++ b/data/plugins/treeview.lua
@@ -231,8 +231,10 @@ function TreeView:on_mouse_pressed(button, x, y, clicks)
         -- 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)
+        if core.is_project_folder(dirname) then
+          core.scan_project_folder(dirname, filename)
+          self:invalidate_cache(dirname)
+        end
       end
       hovered_item.expanded = not hovered_item.expanded
     end