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:
@@ -9,7 +9,7 @@ local FileSelector = {}
|
|||||||
|
|
||||||
--- @class FileSelector
|
--- @class FileSelector
|
||||||
--- @field id integer
|
--- @field id integer
|
||||||
--- @field selected_filepaths string[]
|
--- @field selected_filepaths string[] Absolute paths
|
||||||
--- @field event_handlers table<string, function[]>
|
--- @field event_handlers table<string, function[]>
|
||||||
|
|
||||||
---@alias FileSelectorHandler fun(self: FileSelector, on_select: fun(filepaths: string[] | nil)): nil
|
---@alias FileSelectorHandler fun(self: FileSelector, on_select: fun(filepaths: string[] | nil)): nil
|
||||||
@@ -181,9 +181,17 @@ function FileSelector:get_filepaths()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local selected_filepaths_set = {}
|
||||||
|
for _, abs_path in ipairs(self.selected_filepaths) do
|
||||||
|
selected_filepaths_set[abs_path] = true
|
||||||
|
end
|
||||||
|
|
||||||
return vim
|
return vim
|
||||||
.iter(filepaths)
|
.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()
|
:totable()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user