From 658739261d8ed28f5d905b19c22acb7011192a4d Mon Sep 17 00:00:00 2001 From: Brian Di Palma <1597820+briandipalma@users.noreply.github.com> Date: Tue, 20 Jan 2026 14:02:02 +0000 Subject: [PATCH] feat(view): Add toggle staged keymap support --- lua/codediff/ui/explorer/actions.lua | 7 ++++--- lua/codediff/ui/view/keymaps.lua | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lua/codediff/ui/explorer/actions.lua b/lua/codediff/ui/explorer/actions.lua index 4c7f138..7a07bd5 100644 --- a/lua/codediff/ui/explorer/actions.lua +++ b/lua/codediff/ui/explorer/actions.lua @@ -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 if group == "staged" then -- Unstage file diff --git a/lua/codediff/ui/view/keymaps.lua b/lua/codediff/ui/view/keymaps.lua index 48bacce..8fbf933 100644 --- a/lua/codediff/ui/view/keymaps.lua +++ b/lua/codediff/ui/view/keymaps.lua @@ -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!) -- ======================================================================== @@ -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