feat nvim: menu enable gitsigns

This commit is contained in:
Yuan Chiu 2025-06-02 21:43:36 +08:00
parent 88dbefae00
commit d965bd5d66
Signed by: yuan
GPG Key ID: 50FBE4156404B98D

View File

@ -22,8 +22,40 @@ return {
-- clicked buf
local buf = vim.api.nvim_win_get_buf(vim.fn.getmousepos().winid)
local options = vim.bo[buf].ft == "neo-tree" and "neo-tree" or "default"
local ft = vim.bo[buf].ft
-- 處理選單內容判斷邏輯
local gitsigns = require("gitsigns")
local hunks = gitsigns.get_hunks and gitsigns.get_hunks(buf)
local mouse = vim.fn.getmousepos()
local in_signcolumn = mouse.wincol <= vim.fn.getwininfo(mouse.winid)[1].textoff
local is_git_buf = vim.b[buf].gitsigns_head ~= nil
local has_hunks = hunks and #hunks > 0
local options
if ft == "neo-tree" then
options = "neo-tree"
elseif in_signcolumn and is_git_buf and has_hunks then
options = "gitsigns"
else
options = "default"
end
-- -- Debug用途
-- local name = vim.api.nvim_buf_get_name(buf)
-- local lsp = vim.lsp.get_clients({ bufnr = buf })
-- vim.notify("👉 Buffer: " .. buf ..
-- "\nFile: " .. name ..
-- "\nFiletype: " .. ft ..
-- "\nGitsigns Head: " .. vim.inspect(vim.b[buf].gitsigns_head) ..
-- "\nHas Hunks: " .. tostring(has_hunks) ..
-- "\nMouse Col: " .. mouse.wincol ..
-- "\nText Offset: " .. vim.fn.getwininfo(mouse.winid)[1].textoff ..
-- "\nIn SignColumn: " .. tostring(in_signcolumn) ..
-- "\nLSP: " .. tostring(#lsp > 0) ..
-- "\n🧭 Menu: " .. options, vim.log.levels.INFO
-- )
require("menu").open(options, { mouse = true })
end, {})