Skip to content

Commit 7021848

Browse files
feat(#2349): add "right_align" option for renderer.icons.*_placement (#2846)
* feat(icon_placement): Allow right_align icon_placemente for decorator using ext_marks nvim api * feat(icon_placement): Allow right_align icon_placemente for decorator using ext_marks nvim api feat(icon_placement): Allow right_align icon_placemente for decorator using ext_marks nvim api * feat(icon_placement): consolidate doc * fix: extra namespace added to avoid colision between right_align and full_name features * style: rename namespace_id --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
1 parent 6bbc2ec commit 7021848

File tree

6 files changed

+8
-82
lines changed

6 files changed

+8
-82
lines changed

doc/nvim-tree-lua.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,12 +1045,6 @@ Icon order and sign column precedence:
10451045
Hidden icon placement.
10461046
Type: `string`, Default: `"after"`
10471047

1048-
*nvim-tree.renderer.icons.hidden_placement*
1049-
Place where the hidden (dotfile) icon will be rendered.
1050-
Can be `"after"` or `"before"` filename (after the file/folders icons)
1051-
or `"signcolumn"` (requires |nvim-tree.view.signcolumn| enabled).
1052-
Type: `string`, Default: `"after"`
1053-
10541048
*nvim-tree.renderer.icons.bookmarks_placement*
10551049
Bookmark icon placement.
10561050
Type: `string`, Default: `signcolumn`

lua/nvim-tree/explorer/explore.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local M = {}
1515
---@param cwd string
1616
---@param node Node
1717
---@param git_status table
18-
---@return integer filtered_count
18+
---@param parent Explorer
1919
local function populate_children(handle, cwd, node, git_status, parent)
2020
local node_ignored = explorer_node.is_git_ignored(node)
2121
local nodes_by_path = utils.bool_record(node.nodes, "absolute_path")
@@ -35,7 +35,6 @@ local function populate_children(handle, cwd, node, git_status, parent)
3535
if not name then
3636
break
3737
end
38-
local is_dir = t == "directory"
3938

4039
local abs = utils.path_join { cwd, name }
4140
local profile = log.profile_start("explore populate_children %s", abs)
@@ -45,7 +44,7 @@ local function populate_children(handle, cwd, node, git_status, parent)
4544
local filter_reason = parent.filters:should_filter_as_reason(abs, stat, filter_status)
4645
if filter_reason == FILTER_REASON.none and not nodes_by_path[abs] and Watcher.is_fs_event_capable(abs) then
4746
local child = nil
48-
if is_dir and vim.loop.fs_access(abs, "R") then
47+
if t == "directory" and vim.loop.fs_access(abs, "R") then
4948
child = builders.folder(node, abs, name, stat)
5049
elseif t == "file" then
5150
child = builders.file(node, abs, name, stat)

lua/nvim-tree/lib.lua

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ local utils = require "nvim-tree.utils"
55
local events = require "nvim-tree.events"
66
local notify = require "nvim-tree.notify"
77
local explorer_node = require "nvim-tree.explorer.node"
8-
local actions_reloaders = require "nvim-tree.actions.reloaders"
98

109
---@class LibOpenOpts
1110
---@field path string|nil path
@@ -147,10 +146,6 @@ function M.expand_or_collapse(node, toggle_group)
147146
if node.has_children then
148147
node.has_children = false
149148
end
150-
-- TODO: Inspect(node)
151-
152-
-- node.hidden_count = utils.count_hidden_files(node.absolute_path)
153-
-- node.hidden_count = 79
154149

155150
if #node.nodes == 0 then
156151
core.get_explorer():expand(node)

lua/nvim-tree/renderer/builder.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,6 @@ function Builder:format_line(indent_markers, arrows, icon, name, node)
223223
local line = { indent_markers, arrows }
224224
add_to_end(line, { icon })
225225

226-
if node == nil then
227-
add_to_end(line, { name })
228-
return line
229-
end
230-
231226
for i = #M.decorators, 1, -1 do
232227
add_to_end(line, M.decorators[i]:icons_before(node))
233228
end
@@ -470,7 +465,7 @@ end
470465

471466
--- Add the hidden_count for root, since root dir is treated differently
472467
--- from normal directories we need to do it again for root.
473-
--- Also need to sort my depth
468+
--- Also need to sort by depth
474469
---@private
475470
function Builder:build_root_hidden_count()
476471
local root = core.get_explorer()

lua/nvim-tree/renderer/init.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ local M = {}
1212

1313
local SIGN_GROUP = "NvimTreeRendererSigns"
1414

15-
local namespace_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
15+
local namespace_highlights_id = vim.api.nvim_create_namespace "NvimTreeHighlights"
1616
local namespace_extmarks_id = vim.api.nvim_create_namespace "NvimTreeExtmarks"
1717

1818
---@param bufnr number
@@ -30,9 +30,9 @@ local function _draw(bufnr, lines, hl_args, signs, extmarks, virtual_lines)
3030
M.render_hl(bufnr, hl_args)
3131

3232
if vim.fn.has "nvim-0.10" == 1 then
33-
vim.api.nvim_set_option_value("modifiable", true, { buf = bufnr })
33+
vim.api.nvim_set_option_value("modifiable", false, { buf = bufnr })
3434
else
35-
vim.api.nvim_buf_set_option(bufnr, "modifiable", true) ---@diagnostic disable-line: deprecated
35+
vim.api.nvim_buf_set_option(bufnr, "modifiable", false) ---@diagnostic disable-line: deprecated
3636
end
3737

3838
vim.fn.sign_unplace(SIGN_GROUP)
@@ -64,11 +64,11 @@ function M.render_hl(bufnr, hl)
6464
if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then
6565
return
6666
end
67-
vim.api.nvim_buf_clear_namespace(bufnr, namespace_id, 0, -1)
67+
vim.api.nvim_buf_clear_namespace(bufnr, namespace_highlights_id, 0, -1)
6868
for _, data in ipairs(hl) do
6969
if type(data[1]) == "table" then
7070
for _, group in ipairs(data[1]) do
71-
vim.api.nvim_buf_add_highlight(bufnr, namespace_id, group, data[2], data[3], data[4])
71+
vim.api.nvim_buf_add_highlight(bufnr, namespace_highlights_id, group, data[2], data[3], data[4])
7272
end
7373
end
7474
end
@@ -87,7 +87,6 @@ function M.draw()
8787

8888
local builder = Builder:new():build()
8989

90-
-- _draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks)
9190
_draw(bufnr, builder.lines, builder.hl_args, builder.signs, builder.extmarks, builder.virtual_lines)
9291

9392
if cursor and #builder.lines >= cursor[1] then

lua/nvim-tree/utils.lua

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
local Iterator = require "nvim-tree.iterators.node-iterator"
22
local notify = require "nvim-tree.notify"
3-
-- local git = require "nvim-tree.git"
4-
-- local filters = require "nvim-tree.explorer.filters"
53

64
local M = {
75
debouncers = {},
@@ -19,49 +17,6 @@ M.is_windows = vim.fn.has "win32" == 1 or vim.fn.has "win32unix" == 1
1917
function M.str_find(haystack, needle)
2018
return vim.fn.stridx(haystack, needle) ~= -1
2119
end
22-
local uv = vim.loop
23-
24-
local function is_dotfile(name)
25-
return name:sub(1, 1) == "."
26-
end
27-
28-
M.count_hidden_files = function(node)
29-
if true then
30-
return 2
31-
end
32-
local count = 0
33-
34-
local handle = uv.fs_scandir(node.absolute_path)
35-
if not handle then
36-
return {}
37-
end
38-
39-
if not handle then
40-
print "Error: Unable to scan directory."
41-
return count
42-
end
43-
44-
local cwd = node.link_to or node.absolute_path
45-
local git_status = git.load_project_status(cwd)
46-
47-
local filter_status = filters.prepare(git_status)
48-
while true do
49-
local name, type = uv.fs_scandir_next(handle)
50-
if not name then
51-
break
52-
end
53-
local abs = M.path_join { cwd, name }
54-
55-
local abs = node.absolute_path
56-
---@type uv.fs_stat.result|nil
57-
local stat = vim.loop.fs_stat(abs)
58-
if not filters.should_filter(abs, stat, filter_status) then
59-
count = count + 1
60-
end
61-
end
62-
63-
return count
64-
end
6520

6621
---@param path string
6722
---@return string|uv.uv_fs_t
@@ -599,17 +554,6 @@ function M.inject_node(f)
599554
end
600555
end
601556

602-
---@param tbl table
603-
---@return table
604-
M.reverse_table = function(tbl)
605-
local size = #tbl
606-
local reversed = {}
607-
for i = size, 1, -1 do
608-
table.insert(reversed, tbl[i])
609-
end
610-
return reversed
611-
end
612-
613557
--- Is the buffer named NvimTree_[0-9]+ a tree? filetype is "NvimTree" or not readable file.
614558
--- This is cheap, as the readable test should only ever be needed when resuming a vim session.
615559
---@param bufnr number|nil may be 0 or nil for current

0 commit comments

Comments
 (0)