Skip to content

Commit 07a4411

Browse files
Add dynamic sizing padding options
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!
1 parent 7944e47 commit 07a4411

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ require("nvim-tree").setup()
7474
require("nvim-tree").setup({
7575
sort_by = "case_sensitive",
7676
view = {
77-
adaptive_size = true,
77+
-- adaptive width (use width = number instead for static width)
78+
width = {
79+
min = 30
80+
-- -1 means no limit
81+
max = -1,
82+
-- set total padding space when resizing (handy for custom status columns)
83+
padding = 3
84+
}
7885
mappings = {
7986
list = {
8087
{ key = "u", action = "dir_up" },

doc/nvim-tree-lua.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,11 +734,16 @@ Window / buffer setup.
734734

735735
*nvim-tree.view.width.min*
736736
Minimum dynamic width.
737-
Type: `string | number | function`, Default: `30`
737+
Type: `string | number | function`, Default: `30`
738738

739739
*nvim-tree.view.width.max*
740740
Maximum dynamic width, -1 for unbounded.
741-
Type: `string | number | function`, Default: `-1`
741+
Type: `string | number | function`, Default: `-1`
742+
743+
*nvim-tree.view.width.padding*
744+
dynamic padding when resizing. Useful for custom status-column
745+
styles.
746+
Type: `number`, Default: `3`
742747

743748
*nvim-tree.view.side*
744749
Side of the tree, can be `"left"`, `"right"`.

lua/nvim-tree/view.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local log = require "nvim-tree.log"
66

77
local DEFAULT_MIN_WIDTH = 30
88
local DEFAULT_MAX_WIDTH = -1
9+
local DEFAULT_PADDING = 3
910

1011
M.View = {
1112
adaptive_size = false,
@@ -250,7 +251,7 @@ local function grow()
250251
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
251252
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
252253
-- 1 column of right-padding to indicate end of path
253-
local padding = 3
254+
local padding = M.View.padding
254255
local resizing_width = M.View.initial_width - padding
255256
local max_width
256257

@@ -517,6 +518,7 @@ function M.setup(opts)
517518
M.View.adaptive_size = true
518519
M.View.width = options.width.min or DEFAULT_MIN_WIDTH
519520
M.View.max_width = options.width.max or DEFAULT_MAX_WIDTH
521+
M.View.padding = options.width.padding or DEFAULT_PADDING
520522
else
521523
M.View.adaptive_size = false
522524
M.View.width = options.width

0 commit comments

Comments
 (0)