From 95dc18da5bbbda8e6bd966920950f4af2a9477da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Thu, 13 Mar 2025 00:23:22 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(nvim):=20diffview=20helper=20f?= =?UTF-8?q?unction=20to=20toggle=20the=20view=20easily?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nvim/lua/plugins/extras/editor/git/diffview.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.config/nvim/lua/plugins/extras/editor/git/diffview.lua b/.config/nvim/lua/plugins/extras/editor/git/diffview.lua index 78184002..37b3c97e 100644 --- a/.config/nvim/lua/plugins/extras/editor/git/diffview.lua +++ b/.config/nvim/lua/plugins/extras/editor/git/diffview.lua @@ -1,11 +1,20 @@ local prefix = "gC" +local function toggle_diffview(cmd) + if next(require("diffview.lib").views) == nil then + vim.cmd(cmd) + else + vim.cmd("DiffviewClose") + end +end return { { "sindrets/diffview.nvim", + -- stylua: ignore keys = { - { "gD", "DiffviewFileHistory", desc = "Diff Repo" }, - { "gd", "DiffviewOpen", desc = "Diff View" }, + { "gD", function() toggle_diffview("DiffviewFileHistory") end, desc = "Diff Repo" }, + { "gd", function() toggle_diffview("DiffviewOpen") end, desc = "Diff View" }, + { "gF", function() toggle_diffview("DiffviewFileHistory %") end, desc = "Diff Current File" }, }, opts = function(_, opts) local actions = require("diffview.actions")