-
-
Notifications
You must be signed in to change notification settings - Fork 623
feat: max_width for adaptive_size #1915
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
That would be the sign column. We need to remember that the user may disable it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution, this will greatly improve the user experience.
Tested mostly OK:
- max_width 30
- max_width function
- max_width function returning garbage, OK as same as width
- max_width percent
- max_width -1
Please:
- Account for
view.signcolumn
and remove magic number feat: max_width for adaptive_size #1915 (comment) - Resolve small window size incorrectness feat: max_width for adaptive_size #1915 (comment)
This comment was marked as resolved.
This comment was marked as resolved.
After an unnecessarily long amount of digging, it turns out that the problem is nvim-tree.lua/lua/nvim-tree/view.lua Lines 300 to 302 in 3ce0a8e
Moving it to the top solves the problem (still no idea why it was resized to that exact value though), but I don't really understand what |
I'm not sure how to respond to this :). I prefer |
Maybe A table would be nice: width = {
adaptive = true,
min = 30,
max = 50,
}, As usual we would need to do a silent refactor. We could even get rid of the adaptive variable. If the user specifies max > min it implies adaptive. Default both to 30. |
Here be dragons. I now vaguely recall some vim dramas around The default Let's not deal with that here. A pragmatic solution may simply be to always specify / percentage calculate a width >=20 |
That's clearly a bug. The padding should be 2 or 0 based on sign column visibility. Pushed a fix. |
Still need a way to specify static size. I propose: width = number -- for static size
width = {min = number, max = number} -- for adaptive |
yy
Nice. No big refactoring required. Users with |
Pushed some changes. Please feel free to revert!
It was hard to resist further refactorings... Needs review and extensive testing from @ramezgerges |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @ramezgerges review
- @ramezgerges implement the "space is the end" indicator for all cases
lua/nvim-tree/view.lua
Outdated
@@ -246,7 +246,7 @@ end | |||
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) | |||
local padding = 3 | |||
local padding = M.View.winopts.signcolumn and 2 or 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add an extra character (I.e. 3 instead of 3) as it was previously? I personally find the extra character useful as it indicates that I haven't reached the maximum width yet (i.e. the filename is fully shown and not clipped)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think you got it... I didn't realise that the extra space was useful.
Yes, let's put that back and ensure that it works for max = -1 and max = 30
I like this as well. I also think a useful addition would be to have
So maybe width = number
width = {
adaptive_width = boolean,
min = number
max = number
} with perhaps an NvimTreeToggleAdaptive command or something. Edit: sorry for closing/reopening. Misclicked. Currently on my phone :) I'm a bit busy with exams but I will try to find the time to thoroughly test the commits |
I feel like switching between adaptive and not should be something interested users would do themselves with API. If current API doesn't allow it then it could be expanded. |
Having the API works: allow the user to set width. They can set They could even just set it to an integer when they want fixed and a table when they want adaptive. I'm not quite sure how that API would look; it's a bit different to anything existing. Proposal: release this now, with the padding put back, then we think about API. |
Alright, I finally found time for testing. Some observations:
These are the ones that I could spot for now. I'm not the most perceptive person in the world, I may have missed a problem or two :). One more thing about `MIN_WIDTH`. I can look into `vim.cmd ":wincmd ="` to see if we can find a fix for this. Is this something worth spending time on, or should I just forget about it? I assume that would be a separate PR, but I'm just asking if it's worth looking into. I found the `MIN_WIDTH` fix so uncomfortable :). |
I think you are right here. This is disruptive to the user, and there will be some who are using width < 20 and dealing with any issues. I'll back that change out; width 20 is just a bad hack. I would be most grateful if you could look into the root issue it in a future PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution and all the detailed analysis/testing @ramezgerges
Reverted my very broken "fix" for sign column:
|
resolves #1797
P.S> I'm not sure if this is an issue, but the width of NvimTree doesn't seem to be pixel perfect. The width is off by 2 every time. This is not caused by my changes (I tested this using the provided clean room config).