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

[FEATURE]: Toggle single preview window and show definition automatically when cursor moving in source window. #96

Open
weiyshay opened this issue Mar 19, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@weiyshay
Copy link

weiyshay commented Mar 19, 2023

Is your feature request related to a problem? Please describe.
When reading the code of a completely new project, it is convenient to keep the 'Definition preview' toggled and jump along with the cursor moving in the source code window, in particular with a wide screen which is spacious to have the source window in the left and the preview window in the right.

Invoke/Close 'Goto definition' manually is a bit time-consuming in the case, it will be nice to have an option to enable this feature.

Describe the solution you'd like
Using a single preview window and toggle it, jump to definition automatically by tracing the cursor moving events in the source window.

Describe alternatives you've considered
'srcexpl' in vim plugin, or manually open/close the preview window with shortcuts in neovim.

https://github.com/wenlongche/SrcExpl.git

Additional context
N/A

@weiyshay weiyshay added the enhancement New feature or request label Mar 19, 2023
@rmagatti
Copy link
Owner

Hey, it's an interesting idea. Though if the feature is built it should be easily disabled since it can fairly easily get in the way.

Until then, you can setup something yourself.

Somewhere in your lua config:

local group = vim.api.nvim_create_augroup("constant_peek", {})

vim.api.nvim_create_autocmd("CursorHold", {
  pattern = { "*.*" },
  group = group,
  callback = function()
    require("goto-preview").goto_preview_definition {
      focus_on_open = false,
      dismiss_on_move = true,
    }
  end,
})

@weiyshay
Copy link
Author

Ronnie,
It is pretty cool and what I am looking for in general. It will be nice if:

  1. Toggle the preview window as a split window to replace a popup one.
  2. With an 'Enter' key event in preview window to go to the definition in the main editor buffer.

Can you help to get the magic? :) Thank you very much!

图片

@rmagatti
Copy link
Owner

Hey

  1. You can just use normal vim window movements: https://github.com/rmagatti/goto-preview#window-manipulation
  2. I'm not sure what you mean on this one

@weiyshay
Copy link
Author

weiyshay commented Jul 20, 2023

Hi,

  1. I tried to move the preview window to the right, but when I move back to the source buf and a new preview window pops up afterwards. Anyway to show one preview window? I have disabled 'stack' option but it didn't work.
  2. I guess it will work if Error opening floating window and mapping issues #1 fixed, so it is ok for now.

My options:

    require("goto-preview").setup {
	width = 120; -- Width of the floating window
	height = 60; -- Height of the floating window
	border = {"↖", "─" ,"┐", "│", "┘", "─", "└", "│"}; -- Border characters of the floating window
	default_mappings = true; -- Bind default mappings
	debug = false; -- Print debug information
	opacity = nil; -- 0-100 opacity level of the floating window where 100 is fully transparent.
	resizing_mappings = true; -- Binds arrow keys to resizing the floating window.
        post_open_hook = function(bufr)
            jump_func(bufr)
        end,
	post_close_hook = nil; -- A function taking two arguments, a buffer and a window to be ran as a hook.
	references = { -- Configure the telescope UI for slowing the references cycling window.
	telescope = require("telescope.themes").get_dropdown({ hide_preview = false })
	};
	-- These two configs can also be passed down to the goto-preview definition and implementation calls for one off "peak" functionality.
	focus_on_open = true; -- Focus the floating window when opening it.
	dismiss_on_move = false; -- Dismiss the floating window when moving the cursor.
	force_close = true, -- passed into vim.api.nvim_win_close's second argument. See :h nvim_win_close
	bufhidden = "wipe", -- the bufhidden option to set on the floating window. See :h bufhidden
	stack_floating_preview_windows = false, -- Whether to nest floating windows
	preview_window_title = { enable = true, position = "left" }, -- Whether to set the preview window title as the filename
}

Screenshots:

  1. preview window to right
图片
  1. New preview window pops up.
图片

@rmagatti
Copy link
Owner

Hey @weiyshay would you mind recording a video? I'm still not sure I get what issue you're running into or what exactly you're trying to accomplish

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

No branches or pull requests

2 participants