Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow maximum height setting for popup #843

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,any>
--- @field preview_max_height integer | nil
--- @field attach_to_untracked boolean
--- @field yadm { enable: boolean }
--- @field worktrees {toplevel: string, gitdir: string}[]
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions lua/gitsigns/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading