@@ -12,6 +12,7 @@ local M = {}
1212
1313local DEFAULT_MIN_WIDTH = 30
1414local DEFAULT_MAX_WIDTH = - 1
15+ local DEFAULT_LINES_EXCLUDED = " root"
1516local DEFAULT_PADDING = 1
1617
1718M .View = {
@@ -303,7 +304,7 @@ function M.open(options)
303304end
304305
305306local function grow ()
306- local starts_at = M .is_root_folder_visible (require (" nvim-tree.core" ).get_cwd ()) and 1 or 0
307+ local starts_at = ( M .is_root_folder_visible (require (" nvim-tree.core" ).get_cwd ()) and M . View . lines_excluded == " root " ) and 1 or 0
307308 local lines = vim .api .nvim_buf_get_lines (M .get_bufnr (), starts_at , - 1 , false )
308309 -- number of columns of right-padding to indicate end of path
309310 local padding = get_size (M .View .padding )
@@ -314,31 +315,25 @@ local function grow()
314315 padding = padding + wininfo [1 ].textoff
315316 end
316317
317- local resizing_width = M .View .initial_width - padding
318- local max_width
319-
320- -- maybe bound max
321- if M .View .max_width == - 1 then
322- max_width = - 1
323- else
324- max_width = get_width (M .View .max_width ) - padding
318+ local final_width = M .View .initial_width
319+ local max_width = math.huge
320+ if M .View .max_width ~= - 1 then
321+ max_width = get_width (M .View .max_width )
325322 end
326323
327324 local ns_id = vim .api .nvim_get_namespaces ()[" NvimTreeExtmarks" ]
328325 for line_nr , l in pairs (lines ) do
329- local count = vim .fn .strchars (l )
326+ local line_width = vim .fn .strchars (l )
330327 -- also add space for right-aligned icons
331328 local extmarks = vim .api .nvim_buf_get_extmarks (M .get_bufnr (), ns_id , { line_nr , 0 }, { line_nr , - 1 }, { details = true })
332- count = count + utils .extmarks_length (extmarks )
333- if resizing_width < count then
334- resizing_width = count
335- end
336- if M .View .adaptive_size and max_width >= 0 and resizing_width >= max_width then
337- resizing_width = max_width
329+ line_width = line_width + utils .extmarks_length (extmarks ) + padding
330+ final_width = math.max (final_width , line_width )
331+ if final_width >= max_width then
332+ final_width = max_width
338333 break
339334 end
340335 end
341- M .resize (resizing_width + padding )
336+ M .resize (final_width )
342337end
343338
344339function M .grow_from_content ()
@@ -600,6 +595,7 @@ function M.configure_width(width)
600595 M .View .adaptive_size = true
601596 M .View .width = width .min or DEFAULT_MIN_WIDTH
602597 M .View .max_width = width .max or DEFAULT_MAX_WIDTH
598+ M .View .lines_excluded = width .lines_excluded or DEFAULT_LINES_EXCLUDED
603599 M .View .padding = width .padding or DEFAULT_PADDING
604600 elseif width == nil then
605601 if M .config .width ~= nil then
0 commit comments