Skip to content

Commit c04db63

Browse files
allow padding function, update docs, rollback readme
1 parent 07a4411 commit c04db63

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ require("nvim-tree").setup()
7474
require("nvim-tree").setup({
7575
sort_by = "case_sensitive",
7676
view = {
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-
}
77+
width = 30
8578
mappings = {
8679
list = {
8780
{ key = "u", action = "dir_up" },

doc/nvim-tree-lua.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,8 @@ Window / buffer setup.
741741
Type: `string | number | function`, Default: `-1`
742742

743743
*nvim-tree.view.width.padding*
744-
dynamic padding when resizing. Useful for custom status-column
745-
styles.
746-
Type: `number`, Default: `3`
744+
extra padding to the right.
745+
Type: `string | number | function`, Default: `1`
747746

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

lua/nvim-tree/view.lua

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +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
9+
local DEFAULT_PADDING = 1
1010

1111
M.View = {
1212
adaptive_size = false,
@@ -103,7 +103,6 @@ local function create_buffer(bufnr)
103103
end
104104

105105
local function get_size(size)
106-
size = size or M.View.width
107106
if type(size) == "number" then
108107
return size
109108
elseif type(size) == "function" then
@@ -114,6 +113,11 @@ local function get_size(size)
114113
return math.floor(vim.o.columns * percent_as_decimal)
115114
end
116115

116+
local function get_width(size)
117+
size = size or M.View.width
118+
return get_size(size)
119+
end
120+
117121
local move_tbl = {
118122
left = "H",
119123
right = "L",
@@ -250,16 +254,18 @@ end
250254
local function grow()
251255
local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0
252256
local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false)
253-
-- 1 column of right-padding to indicate end of path
254-
local padding = M.View.padding
257+
-- number of columns of right-padding to indicate end of path
258+
local padding = get_size(M.View.padding)
259+
print(padding)
260+
255261
local resizing_width = M.View.initial_width - padding
256262
local max_width
257263

258264
-- maybe bound max
259265
if M.View.max_width == -1 then
260266
max_width = -1
261267
else
262-
max_width = get_size(M.View.max_width) - padding
268+
max_width = get_width(M.View.max_width) - padding
263269
end
264270

265271
for _, l in pairs(lines) do
@@ -311,7 +317,7 @@ function M.resize(size)
311317
return
312318
end
313319

314-
local new_size = get_size()
320+
local new_size = get_width()
315321
vim.api.nvim_win_set_width(M.get_winnr(), new_size)
316322

317323
events._dispatch_on_tree_resize(new_size)
@@ -524,7 +530,7 @@ function M.setup(opts)
524530
M.View.width = options.width
525531
end
526532

527-
M.View.initial_width = get_size()
533+
M.View.initial_width = get_width()
528534
end
529535

530536
return M

0 commit comments

Comments
 (0)