diff --git a/lua/gitsigns/config.lua b/lua/gitsigns/config.lua index 00d9413cd..ac858845c 100644 --- a/lua/gitsigns/config.lua +++ b/lua/gitsigns/config.lua @@ -72,6 +72,7 @@ end --- @field current_line_blame_formatter_nc string|Gitsigns.CurrentLineBlameFmtFun --- @field current_line_blame_opts Gitsigns.CurrentLineBlameOpts --- @field preview_config table +--- @field preview_max_height integer | nil --- @field attach_to_untracked boolean --- @field yadm { enable: boolean } --- @field worktrees {toplevel: string, gitdir: string}[] @@ -504,6 +505,13 @@ M.schema = { to `nvim_open_win`. ]], }, + preview_max_height = { + type = 'number', + default = nil, + description = [[ + Optional maximum height value of the popup window. + ]] + }, attach_to_untracked = { type = 'boolean', diff --git a/lua/gitsigns/popup.lua b/lua/gitsigns/popup.lua index d9914341b..b8b5c7361 100644 --- a/lua/gitsigns/popup.lua +++ b/lua/gitsigns/popup.lua @@ -26,6 +26,11 @@ end local function expand_height(winid, nlines, border) local newheight = 0 local maxheight = vim.o.lines - vim.o.cmdheight - (border ~= '' and 2 or 0) + local config = require('gitsigns.config').config + local MAX_HEIGHT = config.preview_max_height or maxheight + if maxheight > MAX_HEIGHT then + maxheight = MAX_HEIGHT + end for _ = 0, 50 do local winheight = api.nvim_win_get_height(winid) if newheight > winheight then @@ -143,6 +148,11 @@ function M.create0(lines, opts, id) local opts1 = vim.deepcopy(opts or {}) opts1.height = opts1.height or #lines -- Guess, adjust later + + local max_height = require('gitsigns.config').config.preview_max_height + if max_height and opts1.height > max_height then + opts1.height = max_height + end opts1.width = opts1.width or bufnr_calc_width(bufnr, lines) local winid = api.nvim_open_win(bufnr, false, opts1)