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

Configuration: auto-focus and auto-hide of preview windows #44

Closed
wookayin opened this issue Nov 16, 2021 · 4 comments · Fixed by #46
Closed

Configuration: auto-focus and auto-hide of preview windows #44

wookayin opened this issue Nov 16, 2021 · 4 comments · Fixed by #46

Comments

@wookayin
Copy link
Contributor

wookayin commented Nov 16, 2021

Thanks for implementing a great plugin! This might be a question or feature request (if missing).

First, how can I prevent the cursor from automatically being moved to the preview window? I would want to "peek" the definition only, not disturbing the cursor on the main buffer. This should be a configurable option for all the methods, such as goto_preview_definition(opts).

Second, I would want to have the preview window automatically closed and dismissed when the cursor moves (assuming the cursor hasn't be taken to the preview window). This is similar to vim-quickui's persist = 0 option. How can I achieve that? Writing a custom post_open_hook function for adding autocmd events would be definitely possible, but is there any chance you'd want to implement this is a built-in option?

@rmagatti
Copy link
Owner

Hey @wookayin I think it's a good idea to support "one off peak" functionality like you mentioned.
With the PR I just created I can do this in my config if I just want a separate key binding for the peak functionality.

vim.api.nvim_set_keymap(
  "n",
  "<leader>pk",
  "<cmd>lua require('goto-preview').goto_preview_definition(false, true)<CR>",
  { noremap = true }
)

Alternatively I also added support for making this the default behaviour by specifying the new configs in the setup function call

require("goto-preview").setup({
  default_mappings = true,
  resizing_mappings = true,
  debug = false,
  -- New
  dismiss_on_move = true,
  focus_on_open = false,
})

Maybe you could test this branch before I merge it?

@rmagatti
Copy link
Owner

Actually I just merged it. Let me know if you run into any problems.

@wookayin
Copy link
Contributor Author

wookayin commented Nov 16, 2021

Thanks for implementing this! However, you could have benefitted from my comments as well before jumping to merging it :) The feature looks good, but there are some things to improve:

  • There are some API issues (see Add option to toggle auto focus on the preview window. #46 comments) in regard to OCP.
  • when dismiss_on_move, I cannot focus on the preview window manually (e.g., via wincmd w). I was thinking that when WinEnter-ed to the preview window, we may not want to dismiss it automatically. Does that sound like a reasonable behavior?

@rmagatti
Copy link
Owner

when dismiss_on_move, I cannot focus on the preview window manually (e.g., via wincmd w). I was thinking that when WinEnter-ed to the preview window, we may not want to dismiss it automatically. Does that sound like a reasonable behavior?

Not just reasonable, expected. I tested this, in fact I just re-tested it with these options.

{
  focus_on_open = false,
  dismiss_on_move = true,
}

And focusing the preview window with wincwd w works perfectly.
How does your config look like?

wookayin added a commit to wookayin/goto-preview that referenced this issue Nov 16, 2021
To make the public APIs open to future extension. See rmagatti#44 and rmagatti#46
for the discussion.
wookayin added a commit to wookayin/goto-preview that referenced this issue Nov 16, 2021
To make the public APIs open to future extension. See rmagatti#44 and rmagatti#46
for the discussion.
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.

2 participants