From b75c83398cd8a8b94cda6cf2a3b84aa782d64699 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Fri, 21 Jul 2023 06:35:48 -0700 Subject: [PATCH 1/2] feat: allow maximum height setting for popup --- lua/gitsigns/config.lua | 8 ++++++++ lua/gitsigns/popup.lua | 5 +++++ 2 files changed, 13 insertions(+) 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..a5b5dc076 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 From f9ad08241eac034207ac8bdbfca51f390c0f0ce2 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Fri, 21 Jul 2023 20:51:31 -0700 Subject: [PATCH 2/2] fix: enforce max height even when popup doesn't try to expand to full window height --- lua/gitsigns/popup.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lua/gitsigns/popup.lua b/lua/gitsigns/popup.lua index a5b5dc076..b8b5c7361 100644 --- a/lua/gitsigns/popup.lua +++ b/lua/gitsigns/popup.lua @@ -148,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)