Skip to content

Add dynamic sizing padding options #1941

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

Conversation

HendrikPetertje
Copy link
Contributor

with neovim/neovim#20621 merged in it is now possible to fully customize the status-column in nvim (the column on the left containing line-numbers, fold info, signs and borders).

A fair few cool implementations have popped up like:

The problem with nvim-tree however is that dynamic sizing doesn't take the custom size of a status column into account and the end of file names get clipped off. This little patch should fix that (and give some examples to help other status_column modders get started).

Thanks for looking at this and thanks for making this amazing plugin, I've been using it for a while and I really like it!

Some screenshots:

Before:
Screenshot 2023-01-24 at 10 13 45

After:
Screenshot 2023-01-24 at 10 13 18

alex-courtis and others added 2 commits January 21, 2023 16:30
with neovim/neovim#20621 merged in it is now
possible to fully customize the status-column in nvim (the column on the
left containing line-numbers, fold info, signs and borders).

A fair few cool implementations have popped up like:
- https://github.com/CKolkey/config/blob/master/nvim/after/plugin/statuscolumn.lua
- https://github.com/luukvbaal/statuscol.nvim
- and my own personal one (based on CKolkey's fantastic work) https://git.hendrikpeter.net/hendrikpeter/pico-vim/-/blob/main/lua/peva/status_column.lua

The problem with nvim-tree however is that dynamic sizing doesn't take
the custom size of a status column into account and the end of file
names get clipped off. This little patch should fix that (and give some
examples to help other status_column modders get started).

Thanks for looking at this and thanks for making this amazing plugin,
I've been using it for a while and I really like it!
Copy link
Contributor Author

@HendrikPetertje HendrikPetertje left a comment

Choose a reason for hiding this comment

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

Notes from self

@@ -74,7 +74,14 @@ require("nvim-tree").setup()
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
adaptive_size = true,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that this is now deprecated, so I updated the example code in the README with the new way of working with dynamic sizes and then tacked my padding options on

Copy link
Member

Choose a reason for hiding this comment

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

Thank you. It seems I forgot to update the README... please update to match help

sort_by = "case_sensitive",

it's only there to provide an example of a simple option to pass to setup.

*nvim-tree.view.width.padding*
dynamic padding when resizing. Useful for custom status-column
styles.
Type: `number`, Default: `3`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be the right docs, padding only really supports a number

Copy link
Member

Choose a reason for hiding this comment

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

It can be a function, even if just for the sake of consistency.

You might wish to increase padding as you increase max, to "balance things out".

@@ -250,7 +251,7 @@ local function grow()
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
-- 1 column of right-padding to indicate end of path
local padding = 3
local padding = M.View.padding
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The big change happens here.

@HendrikPetertje
Copy link
Contributor Author

HendrikPetertje commented Jan 24, 2023

#1930 might be better than my change here, I'll leave the decision to you. (having both the ability to do a bit of padding and read it dynamically could also be an option, i personally like 2 or 3 columns of space to the right)

@alex-courtis
Copy link
Member

alex-courtis commented Jan 26, 2023

#1930 might be better than my change here, I'll leave the decision to you. (having both the ability to do a bit of padding and read it dynamically could also be an option, i personally like 2 or 3 columns of space to the right)

We can do both. Padding at the end is quite nice and there's no reason not to make it customisable.

I'd be most grateful if you merged the above branch and we release them as one.

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.

Please:

  • allow a padding function
  • update readme
  • merge fix-variable-width-sign-number-columns

*nvim-tree.view.width.padding*
dynamic padding when resizing. Useful for custom status-column
styles.
Type: `number`, Default: `3`
Copy link
Member

Choose a reason for hiding this comment

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

It can be a function, even if just for the sake of consistency.

You might wish to increase padding as you increase max, to "balance things out".

@@ -74,7 +74,14 @@ require("nvim-tree").setup()
require("nvim-tree").setup({
sort_by = "case_sensitive",
view = {
adaptive_size = true,
Copy link
Member

Choose a reason for hiding this comment

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

Thank you. It seems I forgot to update the README... please update to match help

sort_by = "case_sensitive",

it's only there to provide an example of a simple option to pass to setup.

@HendrikPetertje
Copy link
Contributor Author

Thanks, I'll give this a look and make the corrections after my workday is done!

@HendrikPetertje HendrikPetertje force-pushed the add-custom-padding-to-dynamic-size branch from c04db63 to 5fa504a Compare January 27, 2023 10:37
…-padding-to-dynamic-size

# Conflicts:
#	lua/nvim-tree/view.lua
@HendrikPetertje
Copy link
Contributor Author

HendrikPetertje commented Jan 27, 2023

That should be it @alex-courtis & @ramezgerges

I think i went through all the todo-items and cleaned things up a bit. I tested the code myself just now and did some experiments with functions and the likes. you can see the first changes here:
5fa504a

and then in the merge commit after that I get rid of the little print() that i had inserted earlier.

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.

Tested OK

width:
20
min/max 20/25
min/max 20/20

sign:
"no"
"yes:4"

number:
true
false

padding:
0
1
2
function

@alex-courtis alex-courtis merged commit e05ed6a into nvim-tree:master Jan 28, 2023
@alex-courtis
Copy link
Member

Many thanks @HendrikPetertje

@zhourrr
Copy link

zhourrr commented Jan 28, 2023

Hi all, I want to thank you for this great plugin and merged feature. I notice that when I toggle the file tree, it prints padding as well. Possibly related to this piece of code
image
It's kind of interrupting the workflow.

if type(wininfo) == "table" and type(wininfo[1]) == "table" then
padding = padding + wininfo[1].textoff
end
print(padding)

Choose a reason for hiding this comment

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

Please remove this stray debug print statement.
This gives me an extra "Press ENTER or type command to continue" prompt with the padding printed, whenever I toggle Nvim tree window.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sorry that was my mistake, the problem was fixed a few days ago in master ^_^

@gegoune
Copy link
Collaborator

gegoune commented Jan 30, 2023

That has been fixed on master. Please update.

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