From 318a45ae08c2d2c0515fa6080aaacaa05bafdf9a Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Mon, 14 Jul 2025 14:34:58 -0700 Subject: [PATCH] fix(file_selector): Correct path comparison for selected files The FileSelector:get_filepaths() function incorrectly filters selected files due to a mismatch in path formats (relative vs. absolute). Fix the issue by converting relative file paths to absolute paths before doing the comparison. Use a set instead of re-scanning the table when filtering out duplicates. --- lua/avante/file_selector.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 29b3418..cdb9412 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -9,7 +9,7 @@ local FileSelector = {} --- @class FileSelector --- @field id integer ---- @field selected_filepaths string[] +--- @field selected_filepaths string[] Absolute paths --- @field event_handlers table ---@alias FileSelectorHandler fun(self: FileSelector, on_select: fun(filepaths: string[] | nil)): nil @@ -181,9 +181,17 @@ function FileSelector:get_filepaths() end end) + local selected_filepaths_set = {} + for _, abs_path in ipairs(self.selected_filepaths) do + selected_filepaths_set[abs_path] = true + end + return vim .iter(filepaths) - :filter(function(filepath) return not vim.tbl_contains(self.selected_filepaths, filepath) end) + :filter(function(filepath) + local abs_filepath = Utils.to_absolute_path(filepath) + return not selected_filepaths_set[abs_filepath] + end) :totable() end