From 3d234325d1ed5411a41260ff92718b4f41540717 Mon Sep 17 00:00:00 2001 From: "simon.mandlik" Date: Sat, 15 Nov 2025 21:11:07 +0100 Subject: [PATCH] feat: `include_root` option --- doc/nvim-tree-lua.txt | 5 +++++ lua/nvim-tree.lua | 1 + lua/nvim-tree/view.lua | 4 +++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 75f29dbb067..68f86a3fca9 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -822,6 +822,10 @@ longest line. Type: `string | number | fun(): number|string` Default: `-1` + *nvim-tree.view.width.include_root* + Include root folder when computing width. + Type: `boolean`, Default: `false` + *nvim-tree.view.width.padding* Extra padding to the right. Type: `number | fun(): number|string` @@ -3323,6 +3327,7 @@ highlight group is not, hard linking as follows: > |nvim-tree.view.side| |nvim-tree.view.signcolumn| |nvim-tree.view.width| +|nvim-tree.view.width.include_root| |nvim-tree.view.width.max| |nvim-tree.view.width.min| |nvim-tree.view.width.padding| diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 18858af14f3..55444078895 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -553,6 +553,7 @@ local ACCEPTED_TYPES = { "table", min = { "string", "function", "number" }, max = { "string", "function", "number" }, + include_root = { "boolean" }, padding = { "function", "number" }, }, }, diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 90f2b033f3e..db5faece4ff 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -12,6 +12,7 @@ local M = {} local DEFAULT_MIN_WIDTH = 30 local DEFAULT_MAX_WIDTH = -1 +local DEFAULT_INCLUDE_ROOT = false local DEFAULT_PADDING = 1 M.View = { @@ -303,7 +304,7 @@ function M.open(options) end local function grow() - local starts_at = M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0 + local starts_at = (M.is_root_folder_visible(require("nvim-tree.core").get_cwd()) and M.View.include_root) and 1 or 0 local lines = vim.api.nvim_buf_get_lines(M.get_bufnr(), starts_at, -1, false) -- number of columns of right-padding to indicate end of path local padding = get_size(M.View.padding) @@ -600,6 +601,7 @@ function M.configure_width(width) M.View.adaptive_size = true M.View.width = width.min or DEFAULT_MIN_WIDTH M.View.max_width = width.max or DEFAULT_MAX_WIDTH + M.View.include_root = width.include_root or DEFAULT_INCLUDE_ROOT M.View.padding = width.padding or DEFAULT_PADDING elseif width == nil then if M.config.width ~= nil then