-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add handling of cursor(+-<num>) for row and column #2
Conversation
I'm not very familiar with lua, so do let me know if something can be done better. I'm also planning to try out some more of the pending implementations |
lua/popup/init.lua
Outdated
@@ -94,7 +94,18 @@ function popup.create(what, vim_options) | |||
|
|||
if vim_options.line then | |||
-- TODO: Need to handle "cursor", "cursor+1", ... | |||
win_opts.row = vim_options.line | |||
if type(vim_options.line) == 'string' then | |||
assert(string.find(vim_options.line,'^cursor') ~= nil, "Invalid option") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the ~= nil
part of the assertion. Just assert(string.find(...),
is enough.
lua/popup/init.lua
Outdated
win_opts.row = vim_options.line | ||
if type(vim_options.line) == 'string' then | ||
assert(string.find(vim_options.line,'^cursor') ~= nil, "Invalid option") | ||
local line = vim.fn.getcurpos()[2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I think we should try and use vim.api
for these things.
Would something like vim.api.nvim_win_get_cursor(0)
work?
lua/popup/init.lua
Outdated
assert(string.find(vim_options.line,'^cursor') ~= nil, "Invalid option") | ||
local line = vim.fn.getcurpos()[2] | ||
if (vim_options.line):match "cursor%+(%d+)" then | ||
line = line + tonumber((vim_options.line):match "cursor%+(%d+)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write a util function that does transformation of cursor+1
-> 1
so that we can re-use it? Or just a local function that we re-use.
Oh! I just remember. |
(and btw, would love to see more of the features implemented. Happy to review any PRs that you work on). Great work! |
This actually works better, since the window is created with the cursor at top-left by default. With the old implementation it was top right I think, not sure why |
Move common code to get cursore-relative position to a local function. Also use relative='cursor' for window options instead of computing relative to editor
@tjdevries I think this is ready, could you take a look? |
Awesome! Thanks :) Let me know if there's something in particular you want to work and/or need help. |
Attempt to handle 'cursor[+-] as the argument for row(line) and column. In the screenshot, cursor is in the first row and first column
