Skip to content

Commit f80120a

Browse files
committed
fix: add tree buffer detection to visual handler for mini.files support
1 parent 1e2cfa6 commit f80120a

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

lua/claudecode/init.lua

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,43 @@ function M._create_commands()
665665
end
666666

667667
local function handle_send_visual(visual_data, _opts)
668-
-- Try tree file selection first
668+
-- Check if we're in a tree buffer first
669+
local current_ft = (vim.bo and vim.bo.filetype) or ""
670+
local current_bufname = (vim.api and vim.api.nvim_buf_get_name and vim.api.nvim_buf_get_name(0)) or ""
671+
672+
logger.debug("command", "Visual handler - tree buffer detection:")
673+
logger.debug("command", " current_ft: '" .. tostring(current_ft) .. "'")
674+
logger.debug("command", " current_bufname: '" .. tostring(current_bufname) .. "'")
675+
676+
local is_tree_buffer = current_ft == "NvimTree"
677+
or current_ft == "neo-tree"
678+
or current_ft == "oil"
679+
or current_ft == "minifiles"
680+
or string.match(current_bufname, "neo%-tree")
681+
or string.match(current_bufname, "NvimTree")
682+
or string.match(current_bufname, "minifiles://")
683+
684+
logger.debug("command", " is_tree_buffer: " .. tostring(is_tree_buffer))
685+
686+
if is_tree_buffer then
687+
local integrations = require("claudecode.integrations")
688+
local files, error = integrations.get_selected_files_from_tree()
689+
690+
if error then
691+
logger.error("command", "ClaudeCodeSend_visual->TreeAdd: " .. error)
692+
return
693+
end
694+
695+
if not files or #files == 0 then
696+
logger.warn("command", "ClaudeCodeSend_visual->TreeAdd: No files selected")
697+
return
698+
end
699+
700+
add_paths_to_claude(files, { context = "ClaudeCodeSend_visual->TreeAdd" })
701+
return
702+
end
703+
704+
-- Fall back to old visual selection logic for non-tree buffers
669705
if visual_data then
670706
local visual_commands = require("claudecode.visual_commands")
671707
local files, error = visual_commands.get_files_from_visual_selection(visual_data)

0 commit comments

Comments
 (0)