Skip to content
9 changes: 7 additions & 2 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ local config = {
},
name = {
trailing_slash = false,
highlight_opened_files = false, -- Requires `enable_opened_markers = true`
highlight_opened_files = false, -- Requires `enable_opened_markers = true`.
-- Take values in { false (no highlight), true (only loaded),
-- "all" (both loaded and unloaded)}. For more information,
-- see the `show_unloaded` config of the `buffers` source.
use_git_status_colors = true,
highlight = "NeoTreeFileName",
},
Expand Down Expand Up @@ -471,7 +474,9 @@ local config = {
bind_to_cwd = true,
follow_current_file = true, -- This will find and focus the file in the active buffer every time
-- the current file is changed while the tree is open.
group_empty_dirs = true, -- when true, empty directories will be grouped together
group_empty_dirs = true, -- when true, empty directories will be grouped together
show_unloaded = false, -- When working with sessions, for example, restored but unfocused buffers
-- are mark as "unloaded". Turn this on to view these unloaded buffer.
window = {
mappings = {
["<bs>"] = "navigate_up",
Expand Down
8 changes: 6 additions & 2 deletions lua/neo-tree/sources/common/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@ M.name = function(config, node, state)
end
end

if config.highlight_opened_files then
local hl_opened = config.highlight_opened_files
if hl_opened then
local opened_buffers = state.opened_buffers or {}
if opened_buffers[node.path] ~= nil then
if
(hl_opened == "all" and opened_buffers[node.path])
or (opened_buffers[node.path] and opened_buffers[node.path].loaded)
then
highlight = highlights.FILE_NAME_OPENED
end
end
Expand Down
3 changes: 2 additions & 1 deletion lua/neo-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,14 @@ end
M.get_opened_buffers = function()
local opened_buffers = {}
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(buffer) and vim.fn.buflisted(buffer) then
if vim.fn.buflisted(buffer) ~= 0 then
local buffer_name = vim.api.nvim_buf_get_name(buffer)
if buffer_name == nil or buffer_name == "" then
buffer_name = "[No Name]#" .. buffer
end
opened_buffers[buffer_name] = {
["modified"] = vim.api.nvim_buf_get_option(buffer, "modified"),
["loaded"] = vim.api.nvim_buf_is_loaded(buffer),
}
end
end
Expand Down