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

Support for opening buffer in the active preview window in the background as a normal buffer #8

Closed
sahilsehwag opened this issue Jun 8, 2021 · 9 comments
Labels
enhancement New feature or request

Comments

@sahilsehwag
Copy link

Sometimes we are navigating the code and while digging some definitions we find some important symbol that we need to understand more carefully(like it keeping it aside and thinking something like I'll come back to this).

It would be better if we can have support to open the buffer in active preview window to a normal buffer (without loosing the focus of floating preview)

@sahilsehwag sahilsehwag changed the title Support for opening current buffer in the active window in the background as a normal buffer Support for opening buffer in the active preview window in the background as a normal buffer Jun 8, 2021
@rmagatti
Copy link
Owner

rmagatti commented Jun 8, 2021

hey @sahilsehwag there's some support for this with regular Vim window movements.
If you have a preview float focused, you can do <C-w>j for example to turn that float into a regular split window.

That said there are some UI issues that happen when you do that currently since the borders are not removed. I can probably fix the UI issues in the plugin though.

Another thing to note is that the plugin still keeps track of that window, so if you trigger the binding to close all the windows, that window you just moved to a split would also close.

Could potentially also be tweaked but I'd like to put more thought into what would be a desired workflow first.

@rmagatti rmagatti added the enhancement New feature or request label Jun 8, 2021
@rmagatti
Copy link
Owner

Just to give you an example of what I mean.

2021-06-11 01 55 23

@sahilsehwag
Copy link
Author

sahilsehwag commented Jun 11, 2021

Hey, this satisfies one of the flow, another flow that would be great to have is(I am not sure if vim supports it), open the buffer in background without losing/closing the current preview window(s) ?

The main usecase for the second flow is that, sometimes we want to keep digging into definitions, and along the way, we might find some definitions that we want analyse further, but we also don't want to lose the current location of preview window, so the thought process for the second flow is, this definition needs more understanding, therefore I'll come back to it(that's why opening in background without closing the preview windows), in the meantime, let's keep jumping inside to more definitions

Does this makes sense? or does this sounds feasible?

@rmagatti
Copy link
Owner

I see, you could add mappings to do :badd % or something similar to add a buffer to the buffer list based on the currently focused floating preview's buffer but not switch to it or lose focus on your current flow.

I think this would be possible to support in goto-preview as part of the default mappings, those assume a particular flow ofc, but if you're opting into using default mappings, that's probably okay/expected.

@rmagatti
Copy link
Owner

Hey. So one way you could make this happen is adding your own mapping in the post_open_hook function to send the preview window to a tag CTRL + w T would do that for example. The downside here is you'd focus the newly created tab, but you could always navigate back. Either that or find a way to not focus a tab on creation.

@rmagatti
Copy link
Owner

Closing this as it is technically supported and really just depends on how one wants to use do it.

@shaeinst
Copy link

@rmagatti i tried with :badd to add current floating window to buffer list, but i don't see any new added buffer in buffer list. (:buffers)

I see, you could add mappings to do :badd % or something similar to add a buffer to the buffer list based on the currently focused floating preview's buffer but not switch to it or lose focus on your current flow.

also, an example would be grateful for post_open_hook

Hey. So one way you could make this happen is adding your own mapping in the post_open_hook function to send the preview window to a tag CTRL + w T would do that for example

@rmagatti
Copy link
Owner

@shaeinst ah right, I think I was wrong before, instead of :badd %, all you need to do is set buflisted while having the preview window focused. So something like this for the post_open_hook function.

  post_open_hook = function()
    vim.api.nvim_buf_set_option(vim.api.nvim_get_current_buf(), "buflisted")
  end

@shaeinst
Copy link

thanks.
i think vim.api.nvim_buf_set_option takes three arguments

vim.api.nvim_buf_set_option(vim.api.nvim_get_current_buf(), "buflisted")

so following would work

  	post_open_hook = function()
		-- add preview window to buffer list
		local buffer_num = vim.api.nvim_get_current_buf() -- current buffer
		vim.api.nvim_buf_set_option(buffer_num, "buflisted", true)
	end;

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

3 participants