Skip to content

Commit 27fb7bf

Browse files
committed
fix: fixes #89, correct window stealing prevention logic
1 parent 5b6205c commit 27fb7bf

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lua/neo-tree.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,21 @@ M.setup = function(config)
259259
end
260260
local prior_type = vim.api.nvim_buf_get_option(prior_buf, "filetype")
261261
if prior_type == "neo-tree" and vim.bo.filetype ~= "neo-tree" then
262-
local bufname = vim.fn.bufname()
262+
local current_tabnr = vim.api.nvim_get_current_tabpage()
263+
local neo_tree_tabnr = vim.api.nvim_buf_get_var(prior_buf, "neo_tree_tabnr")
264+
if neo_tree_tabnr ~= current_tabnr then
265+
-- This a new tab, so the alternate being neo-tree doesn't matter.
266+
return
267+
end
268+
local neo_tree_winid = vim.api.nvim_buf_get_var(prior_buf, "neo_tree_winid")
269+
local current_winid = vim.api.nvim_get_current_win()
270+
if neo_tree_winid ~= current_winid then
271+
-- This is not the neo-tree window, so the alternate being neo-tree doesn't matter.
272+
return
273+
end
274+
275+
local bufname = vim.api.nvim_buf_get_name(0)
276+
log.debug("redirecting buffer " .. bufname .. " to new split")
263277
vim.cmd("b#")
264278
-- Using schedule at this point fixes problem with syntax
265279
-- highlighting in the buffer. I also prevents errors with diagnostics

lua/neo-tree/sources/filesystem/lib/filter.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ M.show_filter = function(state, search_as_you_type)
4040
fs.reset_search()
4141
else
4242
state.search_pattern = value
43-
fs.refresh(function()
43+
manager.refresh("filesystem", function()
4444
-- focus first file
4545
local nodes = renderer.get_all_visible_nodes(state.tree)
4646
for _, node in ipairs(nodes) do

lua/neo-tree/ui/renderer.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ local create_window = function(state)
429429
if type(state.bufnr) == "number" then
430430
local bufname = string.format("neo-tree %s [%s]", state.name, state.tabnr)
431431
vim.api.nvim_buf_set_name(state.bufnr, bufname)
432+
vim.api.nvim_buf_set_var(state.bufnr, "neo_tree_source", state.name)
433+
vim.api.nvim_buf_set_var(state.bufnr, "neo_tree_winid", state.winid)
434+
vim.api.nvim_buf_set_var(state.bufnr, "neo_tree_tabnr", state.tabnr)
432435
end
433436

434437
win:on({ "BufDelete" }, function()

0 commit comments

Comments
 (0)