Skip to content

Commit f3573d2

Browse files
committed
_get_filename_offset
1 parent 2ad6125 commit f3573d2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lua/nvim-tree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ local function setup_autocommands(opts)
479479
end
480480

481481
if opts.modified.enable then
482+
-- TODO: :wq doesn't update properly
482483
create_nvim_tree_autocmd("BufModifiedSet", {
483484
callback = function()
484485
utils.debounce("BufModifiedSet:modified_files", opts.modified.debounce_delay, function()

lua/nvim-tree/renderer/builder.lua

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,7 @@ function Builder:_build_folder(node, padding, git_hl, git_icons_tbl)
143143
local git_icons = self:_unwrap_git_data(git_icons_tbl, offset + #icon + (self.is_git_after and #foldername + 1 or 0))
144144
local modified_icon = self:_get_modified_icon(node)
145145

146-
-- TODO: this is duplicated logic with _build_file & _build_symlink
147-
local fname_starts_at = offset
148-
+ #icon
149-
+ (self.is_git_after and 0 or #git_icons)
150-
+ (self.modified.placement ~= "before" and 0 or #modified_icon)
146+
local fname_starts_at = self._get_filename_offset(offset, icon, git_icons, modified_icon)
151147
local line = self:_format_line(padding .. icon, foldername, git_icons, modified_icon)
152148
self:_insert_line(line)
153149

@@ -197,6 +193,18 @@ function Builder:_format_line(before, after, git_icons, modified_icon)
197193
)
198194
end
199195

196+
---@param offset integer
197+
---@param icon string
198+
---@param git_icons string
199+
---@param modified_icon string
200+
---@return integer
201+
function Builder:_get_filename_offset(offset, icon, git_icons, modified_icon)
202+
return offset
203+
+ #icon
204+
+ (self.is_git_after and 0 or #git_icons)
205+
+ (self.modified.placement ~= "before" and 0 or #modified_icon)
206+
end
207+
200208
function Builder:_build_symlink(node, padding, git_highlight, git_icons_tbl)
201209
local offset = string.len(padding)
202210

@@ -217,6 +225,7 @@ function Builder:_build_symlink(node, padding, git_highlight, git_icons_tbl)
217225

218226
self:_insert_highlight(
219227
link_highlight,
228+
-- TODO: is this a bug? where's icon?
220229
offset + (self.is_git_after and 0 or #git_icons) + (self.modified.placement ~= "before" and 0 or #modified_icon),
221230
string.len(line)
222231
)
@@ -258,9 +267,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl, unload
258267
local modified_icon = self:_get_modified_icon(node)
259268
self:_insert_line(self:_format_line(padding .. icon, node.name, git_icons, modified_icon))
260269

261-
local git_icons_length = self.is_git_after and 0 or #git_icons
262-
local modified_icon_length = self.modified.placement ~= "before" and 0 or #modified_icon
263-
local col_start = offset + #icon + git_icons_length + modified_icon_length
270+
local col_start = self._get_filename_offset(offset, icon, git_icons, modified_icon)
264271
local col_end = col_start + #node.name
265272

266273
if vim.tbl_contains(self.special_files, node.absolute_path) or vim.tbl_contains(self.special_files, node.name) then
@@ -275,7 +282,7 @@ function Builder:_build_file(node, padding, git_highlight, git_icons_tbl, unload
275282
and vim.fn.bufloaded(node.absolute_path) > 0
276283
and vim.fn.bufnr(node.absolute_path) ~= unloaded_bufnr
277284
if should_highlight_opened_files then
278-
self:_highlight_opened_files(node, offset, #icon, git_icons_length)
285+
self:_highlight_opened_files(node, offset, #icon, self.is_git_after and 0 or #git_icons)
279286
end
280287

281288
if git_highlight then

0 commit comments

Comments
 (0)