Allow cursor entering hover window with multiple calls in a row
Opened this issue · 8 comments
A bit of an inverse of this issue: #19
I updated the plugin and calling hover
multiple times no longer 'jumps' the cursor into the window. Now instead, I have to use window functions in nvim to get there. I quite liked the "press K twice to jump inside" feature.
:)
Thanks! <3
I think
preview_window = true,
also broke, not sure
@lewis6991 I see that you marked this as “not planned”. So I am wondering, is there a reliable way of jumping into the Hover window with the cursor?
It seems I need to be inside the window in order to scroll up/down, and the swap-window functions from NVIM are not reliable to jump into the hover window.
I Liked that too, I'm trying to think if there is a good way to get this rolling again, do you know how to get it working, @Sleepful, or @lewis6991?
I Imagine some sort of.. autocmd that happened to set a temporary keymap if a hover was opened, then unset it if the hover closes... it's probably not hard to accomplish..
I added the function below to util.lua
:
function M.switch_to_preview()
local current_win = api.nvim_get_current_win()
local windows = api.nvim_list_wins()
local next_win
-- Find the next window
for i, win in ipairs(windows) do
if win == current_win then
next_win = windows[(i % #windows) + 1]
break
end
end
-- Switch focus to the next window
if next_win then
api.nvim_set_current_win(next_win)
end
end
When it runs, if there is a hover window open, it switches to it.
You can import it and call it like this:
local util = require('hover.util')
util.switch_to_preview()
I do not understand the structure of the entire plugin to know the best way to implement this.
However, I did notice that I can include it like below and it switches on the second Shift+k:
local util = require('hover.util')
-- ...
require("hover").register({
name = "MyPlugin",
-- ...
execute = function(opts, done)
-- ...
done({ lines = lines, filetype = "markdown"})
util.switch_to_preview()
end,
})
I hope this helps you work towards the solution and/or function as a temporary workaround.
Edit: I fixed indentation.
Same as #52, maybe you could try the code below.
vim.keymap.set("n", "K", function()
local api = vim.api
local hover_win = vim.b.hover_preview
if hover_win and api.nvim_win_is_valid(hover_win) then
api.nvim_set_current_win(hover_win)
else
require("hover").hover()
end
end, { desc = "hover.nvim" })
Same as #52, maybe you could try the code below.
vim.keymap.set("n", "K", function() local api = vim.api local hover_win = vim.b.hover_preview if hover_win and api.nvim_win_is_valid(hover_win) then api.nvim_set_current_win(hover_win) else require("hover").hover() end end, { desc = "hover.nvim" })
This seems to work for me, thank you !
This should be a default ^ just like a native lsp.hover calling hover twice should move cursor into the window