Skip to content

Commit

Permalink
fix: take border size_delta into account when calculating position
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 26, 2022
1 parent a86c733 commit 454e6fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lua/nui/popup/border.lua
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ end
---@return nui_popup_border_internal_position
local function calculate_position(border)
local position = vim.deepcopy(border.popup._.position)
position.col = position.col - math.floor(border._.size_delta.width / 2 + 0.5)
position.row = position.row - math.floor(border._.size_delta.height / 2 + 0.5)
return position
end

Expand Down
8 changes: 6 additions & 2 deletions tests/nui/popup/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,13 @@ describe("nui.popup", function()

local border_win_config = vim.api.nvim_win_get_config(popup.border.winid)
local border_row, border_col = border_win_config.row[vim.val_idx], border_win_config.col[vim.val_idx]
local border_width, border_height = border_win_config.width, border_win_config.height

eq(border_row, position.row)
eq(border_col, position.col)
local delta_width = border_width - win_config.width
local delta_height = border_height - win_config.height

eq(border_row - math.floor(delta_height / 2 + 0.5), position.row)
eq(border_col - math.floor(delta_width / 2 + 0.5), position.col)
else
eq(row, position.row)
eq(col, position.col)
Expand Down

0 comments on commit 454e6fc

Please sign in to comment.