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.
This commit is contained in:
Dmitry Torokhov
2025-07-14 14:34:58 -07:00
committed by yetone
parent 61e38024dc
commit 318a45ae08

View File

@@ -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<string, function[]>
---@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