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

Implement pos = 'center' option #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
55 changes: 28 additions & 27 deletions lua/popup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,34 @@ function popup.create(what, vim_options)
local win_opts = {}
win_opts.relative = "editor"

-- Feels like maxheigh, minheight, maxwidth, minwidth will all be related
--
-- maxheight Maximum height of the contents, excluding border and padding.
-- minheight Minimum height of the contents, excluding border and padding.
-- maxwidth Maximum width of the contents, excluding border, padding and scrollbar.
-- minwidth Minimum width of the contents, excluding border, padding and scrollbar.
local width = vim_options.width or 1
local height
if type(what) == 'number' then
height = vim.api.nvim_buf_line_count(what)
else
for _, v in ipairs(what) do
width = math.max(width, #v)
end
height = #what
end
win_opts.width = utils.bounded(width, vim_options.minwidth, vim_options.maxwidth)
win_opts.height = utils.bounded(height, vim_options.minheight, vim_options.maxheight)

if vim_options.pos then
if vim_options.pos == 'center' then
vim_options.line = math.floor(((vim.o.lines - win_opts.height) / 2) - 1)
vim_options.col = math.floor((vim.o.columns - win_opts.width) / 2)
else
win_opts.anchor = popup._pos_map[vim_options.pos]
end
end

local cursor_relative_pos = function(pos_str, dim)
assert(string.find(pos_str,'^cursor'), "Invalid value for " .. dim)
win_opts.relative = 'cursor'
Expand Down Expand Up @@ -130,14 +158,6 @@ function popup.create(what, vim_options)
win_opts.col = 0
end

if vim_options.pos then
if vim_options.pos == 'center' then
-- TODO: Do centering..
else
win_opts.anchor = popup._pos_map[vim_options.pos]
end
end

-- posinvert, When FALSE the value of "pos" is always used. When
-- , TRUE (the default) and the popup does not fit
-- , vertically and there is more space on the other side
Expand All @@ -157,25 +177,6 @@ function popup.create(what, vim_options)

win_opts.style = 'minimal'

-- Feels like maxheigh, minheight, maxwidth, minwidth will all be related
--
-- maxheight Maximum height of the contents, excluding border and padding.
-- minheight Minimum height of the contents, excluding border and padding.
-- maxwidth Maximum width of the contents, excluding border, padding and scrollbar.
-- minwidth Minimum width of the contents, excluding border, padding and scrollbar.
local width = vim_options.width or 1
local height
if type(what) == 'number' then
height = vim.api.nvim_buf_line_count(what)
else
for _, v in ipairs(what) do
width = math.max(width, #v)
end
height = #what
end
win_opts.width = utils.bounded(width, vim_options.minwidth, vim_options.maxwidth)
win_opts.height = utils.bounded(height, vim_options.minheight, vim_options.maxheight)

-- textprop, When present the popup is positioned next to a text
-- , property with this name and will move when the text
-- , property moves. Use an empty string to remove. See
Expand Down