Skip to content

Commit c66cbdf

Browse files
authored
fix(#1629): nvim start with file named *NvimTree* opens tree instead of buffer (#1634)
* fix(#1629): nvim start with file named *NvimTree* opens tree instead of buffer * Revert "fix(#1629): nvim start with file named *NvimTree* opens tree instead of buffer" This reverts commit e713607. * fix(#1629): nvim start with file named *NvimTree* treats file as tree * fix(#1629): nvim start with file named *NvimTree* treats file as tree
1 parent 875d38e commit c66cbdf

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

doc/nvim-tree-lua.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Subsequent calls to setup will replace the previous configuration.
204204
},
205205
float = {
206206
enable = false,
207+
quit_on_focus_loss = true,
207208
open_win_config = {
208209
relative = "editor",
209210
border = "rounded",

lua/nvim-tree.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ end
135135

136136
local function find_existing_windows()
137137
return vim.tbl_filter(function(win)
138-
local buf = api.nvim_win_get_buf(win)
139-
return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
138+
return utils.is_nvim_tree_buf(api.nvim_win_get_buf(win))
140139
end, api.nvim_list_wins())
141140
end
142141

lua/nvim-tree/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,15 @@ function M.inject_node(f)
462462
end
463463
end
464464

465+
---Is the buffer a tree? Like /path/to/NvimTree_2 and not a readable file.
466+
---@param bufnr number
467+
---@return boolean
468+
function M.is_nvim_tree_buf(bufnr)
469+
if vim.fn.bufexists(bufnr) then
470+
local bufname = a.nvim_buf_get_name(bufnr)
471+
return vim.fn.fnamemodify(bufname, ":t"):match "^NvimTree_[0-9]+$" and vim.fn.filereadable(bufname) == 0
472+
end
473+
return false
474+
end
475+
465476
return M

lua/nvim-tree/view.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local a = vim.api
33
local M = {}
44

55
local events = require "nvim-tree.events"
6+
local utils = require "nvim-tree.utils"
67

78
local function get_win_sep_hl()
89
-- #1221 WinSeparator not present in nvim 0.6.1 and some builds of 0.7.0
@@ -76,7 +77,7 @@ end
7677

7778
local function wipe_rogue_buffer()
7879
for _, bufnr in ipairs(a.nvim_list_bufs()) do
79-
if not matches_bufnr(bufnr) and a.nvim_buf_get_name(bufnr):match "NvimTree" ~= nil then
80+
if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then
8081
pcall(a.nvim_buf_delete, bufnr, { force = true })
8182
end
8283
end

0 commit comments

Comments
 (0)