Skip to content

feat(view): Floating nvim tree window #1377 #1462

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

Merged
merged 13 commits into from
Aug 6, 2022

Conversation

Khrees
Copy link
Contributor

@Khrees Khrees commented Jul 25, 2022

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

Comment on lines 194 to 200
float = {
enable = false,
-- options passed to nvim_open_win()
relative = "editor",
row = 1,
col = 1,
border = "rounded",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be documented. specially because:

Requires setting nvim-tree.actions.open_file.quit_on_open to true to work properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we require this, quit_on_open should be overridden and set when float.enable is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quit_on_open is now enforced if float.enable is set.

@kyazdani42
Copy link
Member

thanks for the PR :) i think this was asked a lot by people, we could ask them to try it out.
#135

@alex-courtis
Copy link
Member

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

Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very promising, needs UX improvements: #1462 (comment)

I'm tempted to release this early and resolve bugs / improve UX after users raise issues; I expect there will be a lot. Thoughts @kyazdani42 ?

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

Comment on lines 194 to 200
float = {
enable = false,
-- options passed to nvim_open_win()
relative = "editor",
row = 1,
col = 1,
border = "rounded",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we require this, quit_on_open should be overridden and set when float.enable is set.

@kyazdani42
Copy link
Member

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

@Khrees
Copy link
Contributor Author

Khrees commented Jul 26, 2022

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

Yes, but it will be somewhat limited.

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, lets wait for alex's review

@kyazdani42 kyazdani42 requested a review from alex-courtis July 30, 2022 08:36
Copy link
Member

@alex-courtis alex-courtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • nvim-tree float is still not closing on window exit
minimal config

1377

  • open up nvim_open_win config

After playing with this for a while, it became clear that the user needs to be able to set all of the config passed to nvim_open_win, rather than the limited config we allow.

Solution is to allow the user to pass all config, rather than just what we specify in the defaults. The user may pass an invalid config to nvim_open_win however they will get a useful error message.

Added float.open_win_config which is no longer validated, however it is merged. Simplified help to match.

Tidied view.lua: just pass the options to open_win.

0001-add-view.float.open_win_config-skipping-validation.patch.txt

@Khrees
Copy link
Contributor Author

Khrees commented Aug 2, 2022

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

@kyazdani42 kyazdani42 requested a review from alex-courtis August 2, 2022 12:00
@alex-courtis
Copy link
Member

@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
Copy link
Member

Works beautifully with a variety of options.

Let's see how users like it...

@alex-courtis alex-courtis merged commit 7323c81 into nvim-tree:master Aug 6, 2022
@davidsierradz
Copy link
Contributor

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!

@alex-courtis
Copy link
Member

alex-courtis commented Aug 14, 2022

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.

@avalonv
Copy link

avalonv commented Aug 21, 2022

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

@alex-courtis
Copy link
Member

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

:help nvim-tree.view.float

@Khrees Khrees deleted the floating-nvim-tree-window-#1377 branch August 30, 2022 13:00
Almo7aya pushed a commit to Almo7aya/nvim-tree.lua that referenced this pull request Oct 11, 2022
* Simple mock-up of floating nvim-tree window

* Passing whole table to nvim_open_win()

* Run update-help.sh

* Use vim.api alias

* Add comment to float options

* Added `anchor` to float options

* Enabling float window enforces `actions.open_file.quit_on_open`

* Added documentation

* add view.float.open_win_config, skipping validation

* Made nvim-tree window closes when float is enabled

* Close nvim-tree window when out of focus

* Update help

Co-authored-by: Krzysztof Cieśla <[email protected]>
Co-authored-by: Alexander Courtis <[email protected]>
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 this pull request may close these issues.

5 participants