Skip to content

Commit b961b72

Browse files
committed
feat: add complete mini.files multi-selection support\n\nAdds visual mode multi-file selection support to mini.files integration.\nUsers can now select multiple files in mini.files using visual mode and\nsend them all to Claude Code at once.
1 parent 07fa185 commit b961b72

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

lua/claudecode/init.lua

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,54 @@ function M._create_commands()
658658
end
659659

660660
local function handle_send_visual(visual_data, _opts)
661-
-- Try tree file selection first
661+
-- Check if we're in a tree buffer first
662+
local current_ft = (vim.bo and vim.bo.filetype) or ""
663+
local current_bufname = (vim.api and vim.api.nvim_buf_get_name and vim.api.nvim_buf_get_name(0)) or ""
664+
665+
local is_tree_buffer = current_ft == "NvimTree"
666+
or current_ft == "neo-tree"
667+
or current_ft == "oil"
668+
or current_ft == "minifiles"
669+
or string.match(current_bufname, "neo%-tree")
670+
or string.match(current_bufname, "NvimTree")
671+
or string.match(current_bufname, "minifiles://")
672+
673+
if is_tree_buffer then
674+
local integrations = require("claudecode.integrations")
675+
local files, error
676+
677+
-- For mini.files, try to get the range from visual marks
678+
if current_ft == "minifiles" or string.match(current_bufname, "minifiles://") then
679+
local start_line = vim.fn.line("'<")
680+
local end_line = vim.fn.line("'>")
681+
682+
683+
if start_line > 0 and end_line > 0 and start_line <= end_line then
684+
-- Use range-based selection for mini.files
685+
files, error = integrations._get_mini_files_selection_with_range(start_line, end_line)
686+
else
687+
-- Fall back to regular method
688+
files, error = integrations.get_selected_files_from_tree()
689+
end
690+
else
691+
files, error = integrations.get_selected_files_from_tree()
692+
end
693+
694+
if error then
695+
logger.error("command", "ClaudeCodeSend_visual->TreeAdd: " .. error)
696+
return
697+
end
698+
699+
if not files or #files == 0 then
700+
logger.warn("command", "ClaudeCodeSend_visual->TreeAdd: No files selected")
701+
return
702+
end
703+
704+
add_paths_to_claude(files, { context = "ClaudeCodeSend_visual->TreeAdd" })
705+
return
706+
end
707+
708+
-- Fall back to old visual selection logic for non-tree buffers
662709
if visual_data then
663710
local visual_commands = require("claudecode.visual_commands")
664711
local files, error = visual_commands.get_files_from_visual_selection(visual_data)

lua/claudecode/integrations.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,42 @@ 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+
-- Process each line in the range
283+
for line = start_line, end_line do
284+
local entry_ok, entry = pcall(mini_files.get_fs_entry, bufnr, line)
285+
286+
if entry_ok and entry and entry.path and entry.path ~= "" then
287+
-- Extract real filesystem path from mini.files buffer path
288+
local real_path = entry.path
289+
-- Remove mini.files buffer protocol prefix if present
290+
if real_path:match("^minifiles://") then
291+
real_path = real_path:gsub("^minifiles://[^/]*/", "")
292+
end
293+
294+
-- Validate that the path exists
295+
if vim.fn.filereadable(real_path) == 1 or vim.fn.isdirectory(real_path) == 1 then
296+
table.insert(files, real_path)
297+
end
298+
end
299+
end
300+
301+
if #files > 0 then
302+
return files, nil
303+
else
304+
return {}, "No files found in range"
305+
end
306+
end
307+
272308
function M._get_mini_files_selection()
273309
local success, mini_files = pcall(require, "mini.files")
274310
if not success then
@@ -279,6 +315,7 @@ function M._get_mini_files_selection()
279315

280316
local bufnr = vim.api.nvim_get_current_buf()
281317

318+
282319
-- Check if we're in visual mode for multi-selection
283320
local mode = vim.fn.mode()
284321
if mode == "V" or mode == "v" or mode == "\22" then

0 commit comments

Comments
 (0)