Skip to content

Commit bc57a93

Browse files
authored
feat: added highlight for open but unloaded files (#856)
1 parent 5627811 commit bc57a93

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

lua/neo-tree/defaults.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,10 @@ local config = {
213213
},
214214
name = {
215215
trailing_slash = false,
216-
highlight_opened_files = false, -- Requires `enable_opened_markers = true`
216+
highlight_opened_files = false, -- Requires `enable_opened_markers = true`.
217+
-- Take values in { false (no highlight), true (only loaded),
218+
-- "all" (both loaded and unloaded)}. For more information,
219+
-- see the `show_unloaded` config of the `buffers` source.
217220
use_git_status_colors = true,
218221
highlight = "NeoTreeFileName",
219222
},
@@ -473,7 +476,9 @@ local config = {
473476
bind_to_cwd = true,
474477
follow_current_file = true, -- This will find and focus the file in the active buffer every time
475478
-- the current file is changed while the tree is open.
476-
group_empty_dirs = true, -- when true, empty directories will be grouped together
479+
group_empty_dirs = true, -- when true, empty directories will be grouped together
480+
show_unloaded = false, -- When working with sessions, for example, restored but unfocused buffers
481+
-- are mark as "unloaded". Turn this on to view these unloaded buffer.
477482
window = {
478483
mappings = {
479484
["<bs>"] = "navigate_up",

lua/neo-tree/sources/common/components.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,13 @@ M.name = function(config, node, state)
328328
end
329329
end
330330

331-
if config.highlight_opened_files then
331+
local hl_opened = config.highlight_opened_files
332+
if hl_opened then
332333
local opened_buffers = state.opened_buffers or {}
333-
if opened_buffers[node.path] ~= nil then
334+
if
335+
(hl_opened == "all" and opened_buffers[node.path])
336+
or (opened_buffers[node.path] and opened_buffers[node.path].loaded)
337+
then
334338
highlight = highlights.FILE_NAME_OPENED
335339
end
336340
end

lua/neo-tree/utils.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,14 @@ end
257257
M.get_opened_buffers = function()
258258
local opened_buffers = {}
259259
for _, buffer in ipairs(vim.api.nvim_list_bufs()) do
260-
if vim.api.nvim_buf_is_loaded(buffer) and vim.fn.buflisted(buffer) then
260+
if vim.fn.buflisted(buffer) ~= 0 then
261261
local buffer_name = vim.api.nvim_buf_get_name(buffer)
262262
if buffer_name == nil or buffer_name == "" then
263263
buffer_name = "[No Name]#" .. buffer
264264
end
265265
opened_buffers[buffer_name] = {
266266
["modified"] = vim.api.nvim_buf_get_option(buffer, "modified"),
267+
["loaded"] = vim.api.nvim_buf_is_loaded(buffer),
267268
}
268269
end
269270
end

0 commit comments

Comments
 (0)