Skip to content

[Feature request] Allow floating window dimensions be customizable on demand #1512

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

Closed
davidsierradz opened this issue Aug 18, 2022 · 15 comments · Fixed by #1538
Closed

[Feature request] Allow floating window dimensions be customizable on demand #1512

davidsierradz opened this issue Aug 18, 2022 · 15 comments · Fixed by #1538
Labels
feature request PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated

Comments

@davidsierradz
Copy link
Contributor

Is your feature request related to a problem? Please describe.

My use-case would be to open the float window in the center

Describe the solution you'd like

@alex-courtis proposes view.float.open_win_config to be a function that returns a table with the floating window configurations

Describe alternatives you've considered

Tried to calculate the values on entering neovim but with no luck:

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

Additional context

#1462 (comment)

Thanks

@alex-courtis alex-courtis added the PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated label Aug 20, 2022
@pineapplegiant
Copy link

It would be neat if I could call a command to optionally open the floating window centered with the filetree, like how the window is centered in Telescope...

I like to traverse the file tree in a full-screen buffer, but using a floating window would obviously be cooler.

(Also props for a great plugin guys, really neat stuff)

@alex-courtis
Copy link
Member

It would be neat if I could call a command to optionally open the floating window centered with the filetree, like how the window is centered in Telescope...

I'm not quite sure what you mean. Can you not do this with a open_win_config function?

@pineapplegiant
Copy link

@alex-courtis, Not that I know of? Do you know how to call it properly? I have two keymappings: One for toggling the sidebar, the other I'm trying to use for floating window or full screen buffer.

It'd be nice to start an FAQ to get different customizations, since I'm still not too familiar with lua/nvim api. I know with telescope I can pass a table with the config for each call. If I set float = { enable = true} it will affect my other keymap.

My config:

local status, n_tree = pcall(require, "nvim-tree")
if (not status) then return end

local nt_api = require "nvim-tree.api"

n_tree.setup {
	view = {
		-- float = {
		-- 	enable = true,
		-- },
		adaptive_size = false,
		mappings = {
			list = {
				{ key = "<BS>", action = "dir_up" },
				{ key = "L", action = "cd" },
				{ key = "n", action = "create" },
				{ key = "x", action = "remove" },
				{ key = "h", action = "close_node" },
				{ key = "l", action = "dir_down" },
				{ key = "v", action = "vsplit" },
				{ key = "R", action = "refresh" },
			},
		},
	},
	filters = {
		dotfiles = false,
	},
	git = {
		ignore = false,
		enable = true,
		timeout = 400 -- (in ms)
	},
	update_focused_file = {
		enable = true,
		update_cwd = true,
	},
}

vim.keymap.set('n', '<C-n>', 
	function() 
		nt_api.tree.toggle(false, true) 
	end, 
	{ desc = 'Toggle Nvim tree lua with no focus' }
)

--TODO: Not sure how to get this guy to work, open filtree in full window or floating window
vim.keymap.set('n', '<C-r>',
	function() 
		vim.api.nvim_open_win(0, false, n_tree.view.float.open_win_config())
	end, 
	{ desc = 'Open Nvim tree centered in a floating window' }
)

@alex-courtis
Copy link
Member

Do you know how to call it properly?

This functionality is not yet merged: #1538

You can test the branch or wait for merge.

You can then see :help view.float.open_win_config

@alex-courtis
Copy link
Member

vim.keymap.set('n', '<C-r>',

I suspect you are overthinking things. view.float.enable true and an open_win_config function will be sufficient.

@alex-courtis
Copy link
Member

It'd be nice to start an FAQ to get different customizations

An overhaul of mappings, with some accompanying API documentation is a work in progress.

@pineapplegiant
Copy link

pineapplegiant commented Aug 23, 2022

You can test the branch or wait for merge.

Testing it out now..Okay, I think I understand. I don't think there's an API driven way to call the nvim-tree with dynamic configs? Once I set nvim-tree.view.float.enable = true in my initial setup() every call to nvim-tree uses that config, correct?
I cannot for instance pass in a config to each keymap call?

Map something here:nt_api.tree.focus()
Map another keypress here: nt_api.tree.focus(view={float={enable=true}})

An overhaul of mappings, with some accompanying API documentation is a work in progress.

A showcase for such a nice plugin would be awesome! Let me know how I can help/provide screenshots etc.

The PR is still pretty exciting.

Screen Shot 2022-08-22 at 6 15 47 PM

@alex-courtis
Copy link
Member

Once I set nvim-tree.view.float.enable = true in my initial setup() every call to nvim-tree uses that config, correct? I cannot for instance pass in a config to each keymap call?

Map something here:nt_api.tree.focus() Map another keypress here: nt_api.tree.focus(view={float={enable=true}})

That is interesting! Please raise a feature request.

@alex-courtis
Copy link
Member

A showcase for such a nice plugin would be awesome! Let me know how I can help/provide screenshots etc.

That would be greatly appreciated: screenshots with a link to a specific commit to your configuration would be fantastic.

@Chaitanyabsprip
Copy link

Once I set nvim-tree.view.float.enable = true in my initial setup() every call to nvim-tree uses that config, correct? I cannot for instance pass in a config to each keymap call?

Map something here:nt_api.tree.focus() Map another keypress here: nt_api.tree.focus(view={float={enable=true}})

has this been implemented? I came here looking for this exact feature

@alex-courtis
Copy link
Member

Yes! See :help nvim-tree.view.float.open_win_config.

Take a look at this recipe: Center a floating nvim-tree window

@Chaitanyabsprip
Copy link

I want to be able to dynamically tell nvim-tree to open in floating view vs a sidebar view. I don't understand how I'll be able to do that from the link you shared.

@alex-courtis
Copy link
Member

I want to be able to dynamically tell nvim-tree to open in floating view vs a sidebar view. I don't understand how I'll be able to do that from the link you shared.

Sorry; you have to pick one of floating or "sidebar" and stick with it.

What exactly is your use case? This sounds very niche so it is something we would do via API.

@Chaitanyabsprip
Copy link

I want to bind f to open floating nvim-tree and e for sidebar nvim-tree. currently I am re running setup with floating enabled and not, respectively.

@alex-courtis
Copy link
Member

We could do that. Api.tree.open/toggle could take an argument to overrideview.float.enable.

Please raise a feature request so that we can track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request PR please nvim-tree team does not have the bandwidth to implement; a PR will be gratefully appreciated
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants