Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lua/codediff/ui/explorer/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ function M.toggle_stage_entry(explorer, tree)
end

local node = tree:get_node()
if not node or not node.data or node.data.type == "group" or node.data.type == "directory" then

if not node or not node.data then
return
end

local file_path = node.data.path
local group = node.data.group
local file_path = node.data.path or explorer.current_file_path
local group = node.data.group or explorer.current_file_group
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly not sure what's the point of the node.data etc code as the explorer has the data we want so I'd just get rid of the node code.


if group == "staged" then
-- Unstage file
Expand Down
16 changes: 16 additions & 0 deletions lua/codediff/ui/view/keymaps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ function M.setup_all_keymaps(tabpage, original_bufnr, modified_bufnr, is_explore
vim.api.nvim_echo({ { string.format("Put hunk %d", hunk_idx), "None" } }, false, {})
end

-- Helper: Toggle staged
local function toggle_staged()
local explorer_obj = lifecycle.get_explorer(tabpage)
if not explorer_obj then
vim.notify("No explorer found for this tab", vim.log.levels.WARN)
return
end
local explorer = require("codediff.ui.explorer")
explorer.toggle_stage_entry(explorer_obj, explorer_obj.tree)
end

-- ========================================================================
-- Bind all keymaps using unified API (one place for all keymaps!)
-- ========================================================================
Expand Down Expand Up @@ -270,6 +281,11 @@ function M.setup_all_keymaps(tabpage, original_bufnr, modified_bufnr, is_explore
if keymaps.diff_put then
lifecycle.set_tab_keymap(tabpage, "n", keymaps.diff_put, diff_put, { desc = "Put change to other buffer" })
end

-- Toggle stage/unstage (- key, like diffview)
if config.options.keymaps.explorer.toggle_stage then
lifecycle.set_tab_keymap(tabpage, "n", config.options.keymaps.explorer.toggle_stage, toggle_staged, { desc = "Toggle stage/unstage" })
end
end

return M