Skip to content

Commit a34c907

Browse files
committed
prototype with autocmd
1 parent ece4c37 commit a34c907

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

lua/nvim-tree.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,16 @@ local function setup_autocommands(opts)
468468
end,
469469
})
470470
end
471+
472+
if opts.modified.enable then
473+
create_nvim_tree_autocmd("BufModifiedSet", {
474+
callback = function()
475+
utils.debounce("BufModifiedSet:modified_files", opts.modified.debounce_delay, function()
476+
reloaders.reload_explorer()
477+
end)
478+
end,
479+
})
480+
end
471481
end
472482

473483
local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS

lua/nvim-tree/renderer/builder.lua

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ function Builder:configure_git_icons_placement(where)
6868
return self
6969
end
7070

71+
function Builder:configure_modified(modified_icon, modified_placement, modified)
72+
self.modified = modified
73+
self.modified.icon = modified_icon
74+
self.modified.placement = modified_placement
75+
return self
76+
end
77+
7178
function Builder:configure_symlink_destination(show)
7279
self.symlink_destination = show
7380
return self
@@ -206,15 +213,19 @@ function Builder:_highlight_opened_files(node, offset, icon_length, git_icons_le
206213
self:_insert_highlight("NvimTreeOpenedFile", from, to)
207214
end
208215

209-
function Builder:_build_file(node, padding, git_highlight, git_icons_tbl, unloaded_bufnr)
216+
function Builder:_build_file(node, padding, git_highlight, git_icons_tbl, unloaded_bufnr, modified)
210217
local offset = string.len(padding)
211218

212219
local icon = self:_build_file_icon(node, offset)
213220

214221
local git_icons_starts_at = offset + #icon + (self.is_git_after and #node.name + 1 or 0)
215222
local git_icons = self:_unwrap_git_data(git_icons_tbl, git_icons_starts_at)
216223

217-
self:_insert_line(self:_format_line(padding .. icon, node.name, git_icons))
224+
local name = node.name
225+
if modified then
226+
name = name .. self.modified.icon
227+
end
228+
self:_insert_line(self:_format_line(padding .. icon, name, git_icons))
218229

219230
local git_icons_length = self.is_git_after and 0 or #git_icons
220231
local col_start = offset + #icon + git_icons_length
@@ -263,6 +274,8 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
263274
end
264275
end
265276

277+
local modified = vim.fn.bufloaded(node.absolute_path) > 0 and vim.fn.getbufinfo(node.absolute_path)[1].changed == 1
278+
266279
local is_folder = node.nodes ~= nil
267280
local is_symlink = node.link_to ~= nil
268281

@@ -271,7 +284,7 @@ function Builder:_build_line(node, idx, num_children, unloaded_bufnr)
271284
elseif is_symlink then
272285
self:_build_symlink(node, padding, git_highlight, git_icons_tbl)
273286
else
274-
self:_build_file(node, padding, git_highlight, git_icons_tbl, unloaded_bufnr)
287+
self:_build_file(node, padding, git_highlight, git_icons_tbl, unloaded_bufnr, modified)
275288
end
276289
self.index = self.index + 1
277290

lua/nvim-tree/renderer/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function M.draw(unloaded_bufnr)
7070
:configure_opened_file_highlighting(M.config.highlight_opened_files)
7171
:configure_git_icons_padding(M.config.icons.padding)
7272
:configure_git_icons_placement(M.config.icons.git_placement)
73+
:configure_modified(M.config.icons.modified, M.config.icons.modified_placement, M.config.modified)
7374
:configure_symlink_destination(M.config.symlink_destination)
7475
:configure_filter(live_filter.filter, live_filter.prefix)
7576
:build_header(view.is_root_folder_visible(core.get_cwd()))
@@ -100,6 +101,7 @@ end
100101

101102
function M.setup(opts)
102103
M.config = opts.renderer
104+
M.config.modified = opts.modified
103105

104106
_padding.setup(opts)
105107
full_name.setup(opts)

0 commit comments

Comments
 (0)