Skip to content

Commit 0d10aee

Browse files
committed
fix: restore range-based visual selection for mini.files multi-file support
1 parent f80120a commit 0d10aee

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

lua/claudecode/init.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,25 @@ function M._create_commands()
685685

686686
if is_tree_buffer then
687687
local integrations = require("claudecode.integrations")
688-
local files, error = integrations.get_selected_files_from_tree()
688+
local files, error
689+
690+
-- For mini.files, try to get the range from visual marks
691+
if current_ft == "minifiles" or string.match(current_bufname, "minifiles://") then
692+
local start_line = vim.fn.line("'<")
693+
local end_line = vim.fn.line("'>")
694+
695+
logger.debug("command", "Visual marks: start=" .. tostring(start_line) .. ", end=" .. tostring(end_line))
696+
697+
if start_line > 0 and end_line > 0 and start_line <= end_line then
698+
-- Use range-based selection for mini.files
699+
files, error = integrations._get_mini_files_selection_with_range(start_line, end_line)
700+
else
701+
-- Fall back to regular method
702+
files, error = integrations.get_selected_files_from_tree()
703+
end
704+
else
705+
files, error = integrations.get_selected_files_from_tree()
706+
end
689707

690708
if error then
691709
logger.error("command", "ClaudeCodeSend_visual->TreeAdd: " .. error)

lua/claudecode/integrations.lua

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,48 @@ end
269269
--- @return table files List of file paths
270270
--- @return string|nil error Error message if operation failed
271271

272+
-- Helper function to get mini.files selection using explicit range
273+
function M._get_mini_files_selection_with_range(start_line, end_line)
274+
local success, mini_files = pcall(require, "mini.files")
275+
if not success then
276+
return {}, "mini.files not available"
277+
end
278+
279+
local files = {}
280+
local bufnr = vim.api.nvim_get_current_buf()
281+
282+
local logger = require("claudecode.logger")
283+
logger.debug("integrations", "mini.files range selection: " .. start_line .. " to " .. end_line)
284+
285+
-- Process each line in the range
286+
for line = start_line, end_line do
287+
local entry_ok, entry = pcall(mini_files.get_fs_entry, bufnr, line)
288+
289+
if entry_ok and entry and entry.path and entry.path ~= "" then
290+
-- Extract real filesystem path from mini.files buffer path
291+
local real_path = entry.path
292+
-- Remove mini.files buffer protocol prefix if present
293+
if real_path:match("^minifiles://") then
294+
real_path = real_path:gsub("^minifiles://[^/]*/", "")
295+
end
296+
297+
-- Validate that the path exists
298+
if vim.fn.filereadable(real_path) == 1 or vim.fn.isdirectory(real_path) == 1 then
299+
table.insert(files, real_path)
300+
logger.debug("integrations", " added: " .. real_path)
301+
end
302+
end
303+
end
304+
305+
logger.debug("integrations", "Range selection found " .. #files .. " files")
306+
307+
if #files > 0 then
308+
return files, nil
309+
else
310+
return {}, "No files found in range"
311+
end
312+
end
313+
272314
function M._get_mini_files_selection()
273315
local success, mini_files = pcall(require, "mini.files")
274316
if not success then

0 commit comments

Comments
 (0)