nvim-tree.lua icon indicating copy to clipboard operation
nvim-tree.lua copied to clipboard

feat(view): Floating nvim tree window #1377

Open Khrees opened this issue 3 years ago • 6 comments

This PR adds option to display nvim-tree window as float. Requires setting nvim-tree.actions.open_file.quit_on_open to true to work properly.

demo

References #1377

Khrees avatar Jul 25 '22 13:07 Khrees

thanks for the PR :) i think this was asked a lot by people, we could ask them to try it out. https://github.com/kyazdani42/nvim-tree.lua/issues/135

kyazdani42 avatar Jul 25 '22 13:07 kyazdani42

Switching away from the nvim-tree window is problematic as the cursor shows in the nvim-tree window. This is a confusing user experience.

Minimal config with quit_on_open and float.enable set

1377

<C-W>w was used to switch windows.

Practical Proposal quit_on_open is insufficient as it only covers one specific case. Close the nvim-tree window when focus is lost.

gitsigns.nvim behaviour

1377-gitsigns

alex-courtis avatar Jul 25 '22 23:07 alex-courtis

I agree we could merge a first version and improve on that. I'm not sure all the UX impacts that will raise. Closing the window when leaving it would also be a good addition i think

kyazdani42 avatar Jul 26 '22 08:07 kyazdani42

@Khrees can you commit to ongoing support / fixes / changes for this feature?

Yes, but it will be somewhat limited.

Khrees avatar Jul 26 '22 09:07 Khrees

@alex-courtis I have applied your patch and made nvim-tree window close on focus lost.

Khrees avatar Aug 02 '22 07:08 Khrees

@alex-courtis I have applied your patch and made nvim-tree window close on focus lost.

Thank you. I can't test / approve until the weekend.

alex-courtis avatar Aug 02 '22 22:08 alex-courtis

Works beautifully with a variety of options.

Let's see how users like it...

alex-courtis avatar Aug 06 '22 05:08 alex-courtis

Hi! Testing and it works super well. Could we allow width, height, col and row to be functions that return numbers? So we can calculate on demand this values. My use-case would be to open the float window in the center, with something like:

local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local _width = screen_w
local _height = screen_h
local width = math.floor(_width)
local height = math.floor(_height)
local center_y = (vim.opt.lines:get() - _height) / 2
local center_x = (screen_w - _width) / 2

Thanks!

davidsierradz avatar Aug 10 '22 13:08 davidsierradz

Hi! Testing and it works super well. Could we allow width, height, col and row to be functions that return numbers? So we can calculate on demand this values. My use-case would be to open the float window in the center, with something like:

local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local _width = screen_w
local _height = screen_h
local width = math.floor(_width)
local height = math.floor(_height)
local center_y = (vim.opt.lines:get() - _height) / 2
local center_x = (screen_w - _width) / 2

Thanks!

Very interesting. Rather than individual functions, we could instead have view.float.open_win_config be a function that returns a complete able of options. Please raise a feature request.

alex-courtis avatar Aug 14 '22 02:08 alex-courtis

Is there a summary for how to enable and test this for someone who just installed the extension?

avalonv avatar Aug 21 '22 21:08 avalonv

Is there a summary for how to enable and test this for someone who just installed the extension?

:help nvim-tree.view.float

alex-courtis avatar Aug 22 '22 02:08 alex-courtis