Skip to content

Commit

Permalink
# This is a combination of 14 commits.tree a88ac1bf9454ffa72e8002a79b…
Browse files Browse the repository at this point in the history
…25012996ed32f0

parent 4601444
author Kiyan <yazdani.kiyan@protonmail.com> 1652514867 +0200
committer Moshe Avni <mavni@netapp.com> 1653224067 +0300

# This is a combination of 13 commits.
# This is the 1st commit message:

feat(renderer): add ability to set git icons in signcolumn (nvim-tree#1242)


# This is the commit message nvim-tree#2:

feat: extension sorter (nvim-tree#1181) (nvim-tree#1264)


# This is the commit message nvim-tree#3:

Revert "nvim-tree#1253 only pad git icons when they are present (nvim-tree#1259)"

This reverts commit 90d7b8e.
fixes nvim-tree#1267

# This is the commit message nvim-tree#4:

fix(renderer): padding when git icons are after the name

fixes nvim-tree#1253

# This is the commit message nvim-tree#5:

fix(renderer): empty space at end of line

fixes nvim-tree#1253

# This is the commit message nvim-tree#6:

add fish performance tip to README.md
# This is the commit message nvim-tree#7:

feat(live-filter): add ability to live filter out nodes in the tree (nvim-tree#1056)


# This is the commit message nvim-tree#8:

feat: reload explorer on buf enter (nvim-tree#1265)


# This is the commit message nvim-tree#9:

chore(config): auto resize the tree by default when opening a file.

config.open_file.auto_resize is now true by default.
Breaking change for default configurations.
See nvim-tree#1275 (comment)

# This is the commit message nvim-tree#10:

chore: remove custom set local implementation

Seems vim.opt_local has been fixed.
see neovim/neovim#14670

# This is the commit message nvim-tree#11:

refactor: simplify opening file in new tab

fixes nvim-tree#1271. Also fixes opening a file in new tab when close_on_open was
true.

This introduces breaking change since we don't do any extra behavior
and let the buffer be opened by the tree.
The previous behavior was a bit old and i believe this should've been
fixed by now.
Reference this commit if unexpected behavior appears while opening files
in new tabs from nvim-tree.

# This is the commit message nvim-tree#12:

feat: optional path argument for NvimTreeToggle and NvimTreeFindFileToggle (nvim-tree#1276)


# This is the commit message nvim-tree#13:

Ignore case when removing default mappings

# This is the commit message nvim-tree#14:

issue#362: File Management popup menu UI. First Iteration.
  • Loading branch information
kyazdani42 authored and mosheavni committed May 22, 2022
1 parent 4601444 commit a71bb3a
Show file tree
Hide file tree
Showing 24 changed files with 563 additions and 183 deletions.
14 changes: 11 additions & 3 deletions README.md
Expand Up @@ -128,6 +128,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
open_on_tab = false,
sort_by = "name",
update_cwd = false,
reload_on_bufenter = false,
view = {
width = 30,
height = 30,
Expand Down Expand Up @@ -156,7 +157,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
icons = {
webdev_colors = true,
git_placement = "before",
}
},
},
hijack_directories = {
enable = true,
Expand Down Expand Up @@ -201,7 +202,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
},
open_file = {
quit_on_open = false,
resize_window = false,
resize_window = true,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
Expand All @@ -216,6 +217,10 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
cmd = "trash",
require_confirm = true,
},
live_filter = {
prefix = "[FILTER]: ",
always_show_folders = true,
},
log = {
enable = false,
truncate = false,
Expand Down Expand Up @@ -269,6 +274,7 @@ require'nvim-tree'.setup { -- BEGIN_DEFAULT_OPTS
- `S` will prompt the user to enter a path and then expands the tree to match the path
- `.` will enter vim command mode with the file the cursor is on
- `C-k` will toggle a popup with file infos about the file under the cursor
- `f` will allow you to filter nodes dynamically based on regex matching.

### Settings

Expand Down Expand Up @@ -330,6 +336,8 @@ local list = {
{ key = "]c", action = "next_git_item" },
{ key = "-", action = "dir_up" },
{ key = "s", action = "system_open" },
{ key = "f", action = "live_filter" },
{ key = "F", action = "clear_live_filter" },
{ key = "q", action = "close" },
{ key = "g?", action = "toggle_help" },
{ key = "W", action = "collapse_all" },
Expand Down Expand Up @@ -376,7 +384,7 @@ Please attach `$XDG_CACHE_HOME/nvim/nvim-tree.log` if you raise an issue.

*Performance Tips:*

* If you are using fish as an editor shell (which might be fixed in the future), try set `shell=/bin/bash` in your vim config.
* If you are using fish as an editor shell (which might be fixed in the future), try set `shell=/bin/bash` in your vim config. Alternatively, you can [prevent fish from loading interactive configuration in a non-interactive shell](https://github.com/kyazdani42/nvim-tree.lua/issues/549#issuecomment-1127394585).

* Try manually running the git command (see the logs) in your shell e.g. `git --no-optional-locks status --porcelain=v1 --ignored=matching -u`.

Expand Down
53 changes: 44 additions & 9 deletions doc/nvim-tree-lua.txt
Expand Up @@ -31,7 +31,7 @@ closes the tree

|:NvimTreeToggle| *:NvimTreeToggle*

open or close the tree
open or close the tree. Takes an optional path argument.

|:NvimTreeFocus| *:NvimTreeFocus*

Expand All @@ -52,7 +52,8 @@ It will also open the leafs of the tree leading to the file in the buffer
|:NvimTreeFindFileToggle| *:NvimTreeFindFileToggle*

close the tree or change the cursor in the tree for the current bufname,
similar to combination of |:NvimTreeToggle| and |:NvimTreeFindFile|
similar to combination of |:NvimTreeToggle| and |:NvimTreeFindFile|. Takes an
optional path argument.

|:NvimTreeClipboard| *:NvimTreeClipboard*

Expand Down Expand Up @@ -96,6 +97,7 @@ Values may be functions. Warning: this may result in unexpected behaviour.
open_on_tab = false,
sort_by = "name",
update_cwd = false,
reload_on_bufenter = false,
view = {
width = 30,
height = 30,
Expand Down Expand Up @@ -124,7 +126,7 @@ Values may be functions. Warning: this may result in unexpected behaviour.
icons = {
webdev_colors = true,
git_placement = "before",
}
},
},
hijack_directories = {
enable = true,
Expand Down Expand Up @@ -169,7 +171,7 @@ Values may be functions. Warning: this may result in unexpected behaviour.
},
open_file = {
quit_on_open = false,
resize_window = false,
resize_window = true,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
Expand All @@ -184,6 +186,10 @@ Values may be functions. Warning: this may result in unexpected behaviour.
cmd = "trash",
require_confirm = true,
},
live_filter = {
prefix = "[FILTER]: ",
always_show_folders = true,
},
log = {
enable = false,
truncate = false,
Expand Down Expand Up @@ -228,7 +234,7 @@ Will ignore the buffer, when deciding to open the tree on setup.
Type: `boolean`, Default: `false`

*nvim-tree.ignore_ft_on_setup*
List of filetypes that will make `open_on_setup` not open.
List of filetypes that will make `open_on_setup` not open.
You can use this option if you don't want the tree to open
in some scenarios (eg using vim startify).
Type: {string}, Default: {}
Expand All @@ -244,7 +250,7 @@ if the tree was previously open.

*nvim-tree.sort_by*
Changes how files within the same directory are sorted.
Can be one of 'name', 'case_sensitive' or 'modification_time'.
Can be one of 'name', 'case_sensitive', 'modification_time' or 'extension'.
Type: `string`, Default: `"name"`

*nvim-tree.hijack_unnamed_buffer_when_opening*
Expand All @@ -259,6 +265,10 @@ Keeps the cursor on the first letter of the filename when moving in the tree.
Changes the tree root directory on `DirChanged` and refreshes the tree.
Type: `boolean`, Default: `false`

*nvim-tree.reload_on_bufenter*
Automatically reloads the tree on `BufEnter` nvim-tree.
Type: `boolean`, Default: `false`

*nvim-tree.hijack_directories*
hijacks new directory buffers when they are opened (`:e dir`).

Expand Down Expand Up @@ -402,7 +412,7 @@ Window / buffer setup.
Will use only the provided user mappings and not the default otherwise,
extends the default mappings with the provided user mappings.
Type: `boolean`, Default: `false`

*nvim-tree.view.mappings.list*
A list of keymaps that will extend or override the default keymaps.
Type: list of { key: table of strings or string, mode: string (vim-mode), cb: callback function as a string }
Expand Down Expand Up @@ -432,7 +442,10 @@ UI rendering setup
*nvim-tree.renderer.icons.git_placement*
Place where the git icons will be rendered.
After or before the `filename` (after the file/folders icons).
Type: `after` or `before`, Default: `before`
When placed in the signcolumn, the value of signcolumn should be `yes`
for the nvim-tree window.
Note that the diagnostic signs will take precedence over the git signs.
Type: `after`, `before` or `signcolumn`, Default: `before`

*nvim-tree.filters*
Filtering options.
Expand Down Expand Up @@ -487,7 +500,7 @@ Configuration for various actions.

*nvim-tree.actions.open_file.resize_window*
Resizes the tree when opening a file.
Type: `boolean`, Default: `false`
Type: `boolean`, Default: `true`

*nvim-tree.actions.open_file.window_picker*
Window picker configuration.
Expand Down Expand Up @@ -516,6 +529,20 @@ Configuration for various actions.
'+' (system), otherwise, it will be stored in '1' and '"'.
Type: `boolean`, Default: `true`

*nvim-tree.live_filter*
Configurations for the live_filtering feature.
The live filter allows you to filter the tree nodes dynamically, based on
regex matching (see |vim.regex|).
This feature is bound to the `f` key by default.
The filter can be cleared with the `F` key by default.

*nvim-tree.live_filter.prefix*
Prefix of the filter displayed in the buffer.
Type: `string`, Default: `"[FILTER]: "`

*nvim-tree.live_filter.always_show_folders*
Wether to filter folders or not.
Type: `boolean`, Default: `true`

*nvim-tree.log*
Configuration for diagnostic logging.
Expand Down Expand Up @@ -761,6 +788,8 @@ Defaults to:
{ key = "]c", action = "next_git_item" },
{ key = "-", action = "dir_up" },
{ key = "s", action = "system_open" },
{ key = "f", action = "live_filter" },
{ key = "F", action = "clear_live_filter" },
{ key = "q", action = "close" },
{ key = "g?", action = "toggle_help" },
{ key = 'W', action = "collapse_all" },
Expand All @@ -770,6 +799,7 @@ Defaults to:
{ key = "U", action = "toggle_custom" },
}
<

The `list` option in `view.mappings.list` is a table of

- key can be either a string or a table of string (lhs)
Expand Down Expand Up @@ -876,6 +906,11 @@ NvimTreeFileRenamed
NvimTreeFileNew
NvimTreeFileDeleted

There are 2 highlight groups for the live filter feature

NvimTreeLiveFilterPrefix
NvimTreeLiveFilterValue

==============================================================================
vinegar style *nvim-tree-vinegar*

Expand Down
28 changes: 19 additions & 9 deletions lua/nvim-tree.lua
Expand Up @@ -26,12 +26,12 @@ end
---@deprecated
M.on_keypress = require("nvim-tree.actions").on_keypress

function M.toggle(find_file, no_focus)
function M.toggle(find_file, no_focus, cwd)
if view.is_visible() then
view.close()
else
local previous_buf = api.nvim_get_current_buf()
M.open()
M.open(cwd)
if _config.update_focused_file.enable or find_file then
M.find_file(false, previous_buf)
end
Expand Down Expand Up @@ -259,18 +259,18 @@ local function setup_vim_commands()
M.open(res.args)
end, { nargs = "?", complete = "dir" })
api.nvim_create_user_command("NvimTreeClose", view.close, {})
api.nvim_create_user_command("NvimTreeToggle", function()
M.toggle(false)
end, {})
api.nvim_create_user_command("NvimTreeToggle", function(res)
M.toggle(false, false, res.args)
end, { nargs = "?", complete = "dir" })
api.nvim_create_user_command("NvimTreeFocus", M.focus, {})
api.nvim_create_user_command("NvimTreeRefresh", reloaders.reload_explorer, {})
api.nvim_create_user_command("NvimTreeClipboard", copy_paste.print_clipboard, {})
api.nvim_create_user_command("NvimTreeFindFile", function()
M.find_file(true)
end, {})
api.nvim_create_user_command("NvimTreeFindFileToggle", function()
M.toggle(true)
end, {})
api.nvim_create_user_command("NvimTreeFindFileToggle", function(res)
M.toggle(true, false, res.args)
end, { nargs = "?", complete = "dir" })
api.nvim_create_user_command("NvimTreeResize", function(res)
M.resize(res.args)
end, { nargs = 1 })
Expand Down Expand Up @@ -336,6 +336,10 @@ local function setup_autocommands(opts)
if opts.hijack_directories.enable then
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, { callback = M.open_on_directory })
end

if opts.reload_on_bufenter then
create_nvim_tree_autocmd("BufEnter", { pattern = "NvimTree_*", callback = reloaders.reload_explorer })
end
end

local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
Expand All @@ -350,6 +354,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
open_on_tab = false,
sort_by = "name",
update_cwd = false,
reload_on_bufenter = false,
view = {
width = 30,
height = 30,
Expand Down Expand Up @@ -423,7 +428,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
},
open_file = {
quit_on_open = false,
resize_window = false,
resize_window = true,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
Expand All @@ -438,6 +443,10 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
cmd = "trash",
require_confirm = true,
},
live_filter = {
prefix = "[FILTER]: ",
always_show_folders = true,
},
log = {
enable = false,
truncate = false,
Expand Down Expand Up @@ -538,6 +547,7 @@ function M.setup(conf)
require("nvim-tree.view").setup(opts)
require("nvim-tree.lib").setup(opts)
require("nvim-tree.renderer").setup(opts)
require("nvim-tree.live-filter").setup(opts)

setup_vim_commands()
setup_autocommands(opts)
Expand Down
48 changes: 25 additions & 23 deletions lua/nvim-tree/actions/find-file.lua
Expand Up @@ -29,35 +29,37 @@ function M.fn(fname)

local function iterate_nodes(nodes)
for _, node in ipairs(nodes) do
i = i + 1
if not node.hidden then
i = i + 1

if not node.absolute_path or not uv.fs_stat(node.absolute_path) then
break
end

-- match against node absolute and link, as symlinks themselves will differ
if node.absolute_path == fname_real or node.link_to == fname_real then
return i
end
local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator)
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)
local path_matches = node.nodes and (abs_match or link_match)
if path_matches then
if not node.open then
node.open = true
tree_altered = true
if not node.absolute_path or not uv.fs_stat(node.absolute_path) then
break
end

if #node.nodes == 0 then
core.get_explorer():expand(node)
-- match against node absolute and link, as symlinks themselves will differ
if node.absolute_path == fname_real or node.link_to == fname_real then
return i
end
local abs_match = vim.startswith(fname_real, node.absolute_path .. utils.path_separator)
local link_match = node.link_to and vim.startswith(fname_real, node.link_to .. utils.path_separator)
local path_matches = node.nodes and (abs_match or link_match)
if path_matches then
if not node.open then
node.open = true
tree_altered = true
end

if iterate_nodes(node.nodes) ~= nil then
return i
if #node.nodes == 0 then
core.get_explorer():expand(node)
end

if iterate_nodes(node.nodes) ~= nil then
return i
end
-- mandatory to iterate i
elseif node.open then
iterate_nodes(node.nodes)
end
-- mandatory to iterate i
elseif node.open then
iterate_nodes(node.nodes)
end
end
end
Expand Down

0 comments on commit a71bb3a

Please sign in to comment.