diff --git a/data/core/init.lua b/data/core/init.lua index 2794c5f5..d6631970 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -190,6 +190,36 @@ function core.add_project_directory(path) end +local function file_search(files, info) + local filename, type = info.filename, info.type + local inf, sup = 1, #files + while sup - inf > 8 do + local curr = math.floor((inf + sup) / 2) + if system.path_compare(filename, type, files[curr].filename, files[curr].type) then + sup = curr - 1 + else + inf = curr + end + end + repeat + if files[inf].filename == filename then + return inf, true + end + inf = inf + 1 + until inf > sup or system.path_compare(filename, type, files[inf].filename, files[inf].type) + return inf, false +end + + +local function project_scan_add_entry(dir, fileinfo) + local index, match = file_search(dir.files, fileinfo) + if not match then + table.insert(dir.files, index, fileinfo) + dir.is_dirty = true + end +end + + function core.scan_project_subdir(dirname, filename) for _, dir in ipairs(core.project_directories) do if dir.name == dirname then @@ -198,8 +228,8 @@ function core.scan_project_subdir(dirname, filename) if file.filename == filename then if file.scanned then return end local new_files = get_directory_files(dirname, PATHSEP .. filename, {}) - for j, new_file in ipairs(new_files) do - table.insert(dir.files, i + j, new_file) + for _, new_file in ipairs(new_files) do + project_scan_add_entry(dir, new_file) end file.scanned = true return true @@ -285,27 +315,6 @@ function core.project_files_number() end -local function file_search(files, info) - local filename, type = info.filename, info.type - local inf, sup = 1, #files - while sup - inf > 8 do - local curr = math.floor((inf + sup) / 2) - if system.path_compare(filename, type, files[curr].filename, files[curr].type) then - sup = curr - 1 - else - inf = curr - end - end - repeat - if files[inf].filename == filename then - return inf, true - end - inf = inf + 1 - until inf > sup or system.path_compare(filename, type, files[inf].filename, files[inf].type) - return inf, false -end - - local function project_scan_remove_file(watch_id, filepath) local project_dir_entry for i = 1, #core.project_directories do @@ -336,14 +345,16 @@ local function project_scan_add_file(watch_id, filepath) project_dir_entry = core.project_directories[i] end end - if not project_dir_entry or common.match_pattern(filepath, config.ignore_files) then return end + if not project_dir_entry then return end + for fragment in string.gmatch(filepath, "([^/\\]+)") do + if common.match_pattern(fragment, config.ignore_files) then + return + end + end local size_limit = config.file_size_limit * 10e5 local fileinfo = get_project_file_info(project_dir_entry.name, PATHSEP .. filepath, size_limit) - local index, match = file_search(project_dir_entry.files, fileinfo) - if not match then - table.insert(project_dir_entry.files, index, fileinfo) - project_dir_entry.is_dirty = true - return + if fileinfo then + project_scan_add_entry(project_dir_entry, fileinfo) end end diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index cfb88137..a45c7ff6 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -104,9 +104,9 @@ end function TreeView:check_cache() - -- invalidate cache's skip values if project_files has changed for i = 1, #core.project_directories do local dir = core.project_directories[i] + -- invalidate cache's skip values if directory is declared dirty if dir.is_dirty and self.cache[dir.name] then self:invalidate_cache(dir.name) end @@ -219,9 +219,7 @@ function TreeView:on_mouse_pressed(button, x, y, clicks) else if hovered_item.dir.files_limit and not hovered_item.expanded then local dirname = hovered_item.dir.name - if core.scan_project_subdir(dirname, hovered_item.filename) then - self:invalidate_cache(dirname) - end + core.scan_project_subdir(dirname, hovered_item.filename) end hovered_item.expanded = not hovered_item.expanded end diff --git a/src/api/system.c b/src/api/system.c index bf868087..dd6abac4 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -703,7 +703,21 @@ static int f_path_compare(lua_State *L) { return 1; } /* If types are the same compare the files' path alphabetically. */ - lua_pushboolean(L, strcmp(path1 + i, path2 + i) < 0); + int cfr = 0; + int len_min = (len1 < len2 ? len1 : len2); + for (int j = i; j <= len_min; j++) { + if (path1[j] == path2[j]) continue; + if (path1[j] == 0 || path2[j] == 0) { + cfr = (path1[j] == 0); + } else if (path1[j] == PATHSEP || path2[j] == PATHSEP) { + /* For comparison we treat PATHSEP as if it was the string terminator. */ + cfr = (path1[j] == PATHSEP); + } else { + cfr = (path1[j] < path2[j]); + } + break; + } + lua_pushboolean(L, cfr); return 1; }