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

fix: take border size_delta into account when calculating position #204

Merged
merged 1 commit into from
Oct 26, 2022
Merged
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
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