Skip to content

Commit

Permalink
fix(#1629): nvim start with file named *NvimTree* opens tree instead …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
alex-courtis committed Oct 10, 2022
1 parent 875d38e commit c66cbdf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/nvim-tree-lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ Subsequent calls to setup will replace the previous configuration.
},
float = {
enable = false,
quit_on_focus_loss = true,
open_win_config = {
relative = "editor",
border = "rounded",
Expand Down
3 changes: 1 addition & 2 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,7 @@ end

local function find_existing_windows()
return vim.tbl_filter(function(win)
local buf = api.nvim_win_get_buf(win)
return api.nvim_buf_get_name(buf):match "NvimTree" ~= nil
return utils.is_nvim_tree_buf(api.nvim_win_get_buf(win))
end, api.nvim_list_wins())
end

Expand Down
11 changes: 11 additions & 0 deletions lua/nvim-tree/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,15 @@ function M.inject_node(f)
end
end

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

return M
3 changes: 2 additions & 1 deletion lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local a = vim.api
local M = {}

local events = require "nvim-tree.events"
local utils = require "nvim-tree.utils"

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

local function wipe_rogue_buffer()
for _, bufnr in ipairs(a.nvim_list_bufs()) do
if not matches_bufnr(bufnr) and a.nvim_buf_get_name(bufnr):match "NvimTree" ~= nil then
if not matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then
pcall(a.nvim_buf_delete, bufnr, { force = true })
end
end
Expand Down

0 comments on commit c66cbdf

Please sign in to comment.