-
-
Notifications
You must be signed in to change notification settings - Fork 61
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(popup): always use current window when position == "cursor" #338
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #338 +/- ##
=======================================
Coverage 99.04% 99.04%
=======================================
Files 20 20
Lines 2733 2735 +2
=======================================
+ Hits 2707 2709 +2
Misses 26 26 ☔ View full report in Codecov by Sentry. |
@MunifTanjim Any updates? |
What would happen if I open a popup with relative=cursor, then move the cursor to a different window and call The container should still be the initial window where the popup was opened, right? |
Oh, I thought This is how to reproduce the problem I was referring to. And this PR fixes it by making popup always open from the current focused window.
When |
Any updates @MunifTanjim ? |
lua/nui/layout/utils.lua
Outdated
@@ -89,7 +89,7 @@ function mod.get_container_info(position) | |||
|
|||
return { | |||
relative = position.bufpos and "buf" or relative, | |||
size = utils.get_window_size(position.win), | |||
size = utils.get_window_size(relative == "cursor" and 0 or position.win), |
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.
This will just fix the size. But reference to that invalid window id will remain internally.
Can we try this instead?
diff --git a/lua/nui/layout/utils.lua b/lua/nui/layout/utils.lua
index 6f251b5..66efcc3 100644
--- a/lua/nui/layout/utils.lua
+++ b/lua/nui/layout/utils.lua
@@ -137,7 +137,9 @@ function mod.update_layout_config(component_internal, config)
if options.relative then
internal.layout.relative = options.relative
- local fallback_winid = internal.position and internal.position.win or vim.api.nvim_get_current_win()
+ local fallback_winid = internal.position and internal.position.win
+ or internal.layout.relative.type == "cursor" and 0
+ or vim.api.nvim_get_current_win()
internal.position =
vim.tbl_extend("force", internal.position or {}, mod.parse_relative(internal.layout.relative, fallback_winid))
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.
Fair enough. I'll use that instead.
What do you think about this?
Note
It might be better to relative ~= "win" and 0 or position.win
?
Basically the values are relative = "editor"|"win"|"cursor"
, and "editor" case is dealt with above, so they mean the exact same thing for now, but may not be in the future (when new position value is added).
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.
nui.nvim
also accepts this:
nui.nvim/lua/nui/popup/README.md
Lines 229 to 240 in fc59553
Relative to the buffer position: | |
```lua | |
relative = { | |
type = "buf", | |
-- zero-indexed | |
position = { | |
row = 5, | |
col = 5, | |
}, | |
}, | |
``` |
Which internally translates to
win = current_window
bufpos = position_relative_to_buffer_on_current_window
The bufpos
is only valid for a specific buffer, so win
needs to be fixed to a window that contains that buffer.
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.
Oh so it is relative = "editor"|"win"|"cursor"|"buf"
?
Then I'll use relative == "cursor" and 0
.
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.
@MunifTanjim Fixed!
Please squash merge this PR. The commit history is kinda messy.
42cfb30
to
c0e07ad
Compare
Fixes folke/noice.nvim#636.
There are many ways to fix this issue, but I think my approach is the cleanest.
Other options:
internal.position.win
to nil just likewin_config.win
here. (win_config.win
will be nil, butinternal.position.win
is still unchanged and remembers the old value.)nui.nvim/lua/nui/layout/utils.lua
Line 145 in c3c7fd6
win_config
instead ofinternal.position
tomod.get_container_info
here.nui.nvim/lua/nui/layout/utils.lua
Line 156 in c3c7fd6
Basically we need to pass a table with
win = nil
toget_window_size()
that is called insideget_container_info
, or deal with invalidtable.win
and ignore that value inside that function.Note
It might be better to
relative ~= "win" and 0 or position.win
?Basically the values are
relative = "editor"|"win"|"cursor"
, and "editor" case is dealt with above, so they mean the exact same thing for now, but may not be in the future (when new position value is added).