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

Popup cursor relative #12

Open
wants to merge 2 commits 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
35 changes: 20 additions & 15 deletions lua/popup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ function popup.create(what, vim_options)
assert(string.find(pos_str,'^cursor'), "Invalid value for " .. dim)
win_opts.relative = 'cursor'
local line = 0
if (pos_str):match "cursor%+(%d+)" then
line = line + tonumber((pos_str):match "cursor%+(%d+)")
elseif (pos_str):match "cursor%-(%d+)" then
line = line - tonumber((pos_str):match "cursor%-(%d+)")
local m = (pos_str):match "cursor([+-]%d+)"
if m then
line = line + tonumber(m)
end
return line
end
Expand All @@ -114,7 +113,7 @@ function popup.create(what, vim_options)
win_opts.row = vim_options.line
end
else
-- TODO: It says it needs to be "vertically cenetered"?...
-- TODO: It says it needs to be "vertically centered"?...
-- wut is that.
win_opts.row = 0
end
Expand All @@ -126,7 +125,7 @@ function popup.create(what, vim_options)
win_opts.col = vim_options.col
end
else
-- TODO: It says it needs to be "horizontally cenetered"?...
-- TODO: It says it needs to be "horizontally centered"?...
win_opts.col = 0
end

Expand Down Expand Up @@ -157,7 +156,7 @@ function popup.create(what, vim_options)

win_opts.style = 'minimal'

-- Feels like maxheigh, minheight, maxwidth, minwidth will all be related
-- Feels like maxheight, 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.
Expand Down Expand Up @@ -188,11 +187,10 @@ function popup.create(what, vim_options)
if vim_options.hidden then
assert(false, "I have not implemented this yet and don't know how")
else
local should_enter = vim_options.enter
if should_enter == nil then
should_enter = true
end
win_id = vim.api.nvim_open_win(bufnr, should_enter, win_opts)
-- We can't immediately enter tehe window, but have to delay this until after the border has been drawn
-- (see below). This is only required in the case 'relative=cursor' and 'border=true'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this true only for relative=cursor?

-- TODO: Is this a desired behavior or a bug of 'nvim_open_win'?
win_id = vim.api.nvim_open_win(bufnr, false, win_opts)
end


Expand Down Expand Up @@ -283,7 +281,7 @@ function popup.create(what, vim_options)
-- for the top/right/bottom/left border. Optionally
-- followed by the character to use for the
-- topleft/topright/botright/botleft corner.
-- Example: ['-', '|', '-', '|', '┌', '┐', '┘', '└']
-- Example: {'-', '|', '-', '|', '┌', '┐', '┘', '└'}
-- When the list has one character it is used for all.
-- When the list has two characters the first is used for
-- the border lines, the second for the corners.
Expand Down Expand Up @@ -331,6 +329,15 @@ function popup.create(what, vim_options)
border = Border:new(bufnr, win_id, win_opts, border_options)
end

local should_enter = vim_options.enter
if should_enter == nil then
should_enter = true
end

if should_enter then
vim.api.nvim_set_current_win(win_id)
end

if vim_options.highlight then
vim.api.nvim_win_set_option(win_id, 'winhl', string.format('Normal:%s', vim_options.highlight))
end
Expand All @@ -347,7 +354,5 @@ end
function popup.show(self, asdf)
end

popup.show = function()
end

return popup