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

Allow cursor entering hover window with multiple calls in a row #49

Open
Sleepful opened this issue Nov 25, 2023 · 8 comments · May be fixed by #59
Open

Allow cursor entering hover window with multiple calls in a row #49

Sleepful opened this issue Nov 25, 2023 · 8 comments · May be fixed by #59

Comments

@Sleepful
Copy link

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

@Sleepful
Copy link
Author

I think

            preview_window = true,

also broke, not sure

@lewis6991 lewis6991 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2023
@Sleepful
Copy link
Author

@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.

@WillEhrendreich
Copy link

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..

@lewis6991 lewis6991 reopened this Mar 19, 2024
@MasterTemple
Copy link

MasterTemple commented Mar 29, 2024

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.

@gh-liu
Copy link
Contributor

gh-liu commented Apr 24, 2024

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" })

@pyrho
Copy link

pyrho commented Apr 25, 2024

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 !

@Sleepful
Copy link
Author

Thank you @gh-liu 🙏

Sleepful added a commit to Sleepful/.config that referenced this issue Apr 26, 2024
@AThePeanut4 AThePeanut4 linked a pull request Apr 30, 2024 that will close this issue
@dmtrKovalenko
Copy link

This should be a default ^ just like a native lsp.hover calling hover twice should move cursor into the window

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants