-
-
Notifications
You must be signed in to change notification settings - Fork 626
feat: add option to hide root dir path #631
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
Changes from all commits
2ad3e33
4d62ac2
7f148f1
109122b
4be0a36
aa6e674
5ee7324
dd880e3
c588e96
9f7b563
e19eb5c
ddd80af
6f35805
0236b53
c73186c
3ed80fd
08b351a
d969239
a5724d5
2ec39bc
8cba74a
8a1d7b1
fdd632b
e1b13f5
e8a0379
a99ca2a
0022cd7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ function. | |
open_on_tab = false, | ||
hijack_cursor = false, | ||
update_cwd = false, | ||
hide_root_folder = false, | ||
lsp_diagnostics = false, | ||
update_focused_file = { | ||
enable = false, | ||
|
@@ -200,7 +201,10 @@ Here is a list of the options available in the setup call: | |
type: `boolean` | ||
default: false | ||
|
||
*nvim-tree.view* | ||
- |hide_root_folder|: hide the path of the current working directory on top of the tree | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. badly resolved, add a |
||
type: `boolean` | ||
default: false | ||
|
||
- |view|: window / buffer setup | ||
|
||
- |view.width|: width of the window, can be either a `%` string or | ||
|
@@ -547,6 +551,7 @@ applied. | |
|
||
NvimTreeSymlink | ||
NvimTreeFolderName | ||
NvimTreeHideRootFolder | ||
NvimTreeRootFolder | ||
NvimTreeFolderIcon | ||
NvimTreeEmptyFolderName | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,8 +161,15 @@ function M.on_keypress(mode) | |
return keypress_funcs[mode](node) | ||
end | ||
|
||
local hide_root_folder = view.View.hide_root_folder | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too many empty lines here, one suffice :) |
||
if node.name == ".." then | ||
return lib.change_dir("..") | ||
if hide_root_folder then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing or |
||
return lib.unroll_dir(node); | ||
else | ||
return lib.change_dir("..") | ||
end | ||
elseif mode == "cd" and node.entries ~= nil then | ||
return lib.change_dir(lib.get_last_group_node(node).absolute_path) | ||
elseif mode == "cd" then | ||
|
@@ -408,7 +415,8 @@ local DEFAULT_OPTS = { | |
hijack_cursor = false, | ||
update_cwd = false, | ||
lsp_diagnostics = false, | ||
update_focused_file = { | ||
hide_root_folder = false, | ||
update_focused_file = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. badly aligned :) |
||
enable = false, | ||
update_cwd = false, | ||
ignore_list = {} | ||
|
@@ -439,6 +447,10 @@ function M.setup(conf) | |
_config.update_to_buf_dir = opts.update_to_buf_dir | ||
end | ||
|
||
if opts.hide_root_folder then | ||
view.View.hide_root_folder = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if this is a view option, add it to the view config and set it inside the view setup. |
||
end | ||
|
||
require'nvim-tree.colors'.setup() | ||
require'nvim-tree.view'.setup(opts.view or {}) | ||
require'nvim-tree.diagnostics'.setup(opts) | ||
|
@@ -450,4 +462,37 @@ function M.setup(conf) | |
vim.schedule(function() M.on_enter(opts) end) | ||
end | ||
|
||
local function startup_check_new_setup() | ||
local out_config = { | ||
"nvim_tree_disable_netrw", | ||
"nvim_tree_hijack_netrw", | ||
"nvim_tree_auto_open", | ||
"nvim_tree_auto_close", | ||
"nvim_tree_tab_open", | ||
"nvim_tree_hide_root_folder", | ||
"nvim_tree_update_cwd", | ||
"nvim_tree_hijack_cursor", | ||
"nvim_tree_system_open_command", | ||
"nvim_tree_system_open_command_args", | ||
"nvim_tree_follow", | ||
"nvim_tree_follow_update_path", | ||
"nvim_tree_lsp_diagnostics", | ||
"nvim_tree_auto_resize", | ||
"nvim_tree_bindings", | ||
"nvim_tree_disable_keybindings", | ||
"nvim_tree_disable_default_keybindings", | ||
} | ||
|
||
local x = vim.tbl_filter(function(v) | ||
return vim.fn.exists('g:'..v) ~= 0 | ||
end, out_config) | ||
|
||
if #x > 0 then | ||
local msg = "following options are now set in the setup, please read the new documentation for the setup function: " | ||
require'nvim-tree.utils'.echo_warning(msg..table.concat(x, " | ")) | ||
end | ||
end | ||
|
||
vim.defer_fn(startup_check_new_setup, 1000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whole code has been moved to |
||
|
||
return M |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,12 @@ end | |
|
||
local function get_node_at_line(line) | ||
local index = 2 | ||
|
||
local hide_root_folder = view.View.hide_root_folder | ||
if hide_root_folder then | ||
index = 1 | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. badly indented There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also for more concise reading: |
||
|
||
local function iter(entries) | ||
for _, node in ipairs(entries) do | ||
if index == line then | ||
|
@@ -102,6 +108,7 @@ end | |
|
||
function M.get_node_at_cursor() | ||
local winnr = view.get_winnr() | ||
local hide_root_folder = view.View.hide_root_folder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space missing |
||
if not winnr then | ||
return | ||
end | ||
|
@@ -112,7 +119,7 @@ function M.get_node_at_cursor() | |
local help_text = get_node_at_line(line+1)(help_lines) | ||
return {name = help_text} | ||
else | ||
if line == 1 and M.Tree.cwd ~= "/" then | ||
if line == 1 and M.Tree.cwd ~= "/" and not hide_root_folder then | ||
return { name = ".." } | ||
end | ||
|
||
|
@@ -205,7 +212,8 @@ end | |
|
||
function M.set_index_and_redraw(fname) | ||
local i | ||
if M.Tree.cwd == '/' then | ||
local hide_root_folder = view.View.hide_root_folder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space missing here too |
||
if M.Tree.cwd == '/' and hide_root_folder then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this an |
||
i = 0 | ||
else | ||
i = 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ end | |
M.View = { | ||
bufnr = nil, | ||
tabpages = {}, | ||
hide_root_folder = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing space. |
||
winopts = { | ||
relativenumber = false, | ||
number = false, | ||
|
@@ -107,7 +108,7 @@ end | |
local DEFAULT_CONFIG = { | ||
width = 30, | ||
side = 'left', | ||
auto_resize = false, | ||
auto_resize = false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unwanted change |
||
mappings = { | ||
custom_only = false, | ||
list = {} | ||
|
@@ -141,7 +142,7 @@ function M.setup(opts) | |
local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts) | ||
M.View.side = options.side | ||
M.View.width = options.width | ||
M.View.auto_resize = opts.auto_resize | ||
M.View.auto_resize = opts.auto_resize | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bis |
||
if options.mappings.custom_only then | ||
M.View.mappings = options.mappings.list | ||
else | ||
|
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.
indenting :)