Skip to content

Commit 8b27fd4

Browse files
committed
refacto: move target_winid outside of tree
1 parent 74791bb commit 8b27fd4

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lua/nvim-tree/actions/open-file.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ local function open_file_in_tab(filename)
9595
else
9696
-- Switch window first to ensure new window doesn't inherit settings from
9797
-- NvimTree
98-
if lib.Tree.target_winid > 0 and api.nvim_win_is_valid(lib.Tree.target_winid) then
99-
api.nvim_set_current_win(lib.Tree.target_winid)
98+
if lib.target_winid > 0 and api.nvim_win_is_valid(lib.target_winid) then
99+
api.nvim_set_current_win(lib.target_winid)
100100
else
101101
vim.cmd("wincmd p")
102102
end
@@ -133,13 +133,13 @@ function M.fn(mode, filename)
133133

134134
local target_winid
135135
if vim.g.nvim_tree_disable_window_picker == 1 or mode == "edit_no_picker" then
136-
target_winid = lib.Tree.target_winid
136+
target_winid = lib.target_winid
137137
else
138138
target_winid = pick_window()
139139
end
140140

141141
if target_winid == -1 then
142-
target_winid = lib.Tree.target_winid
142+
target_winid = lib.target_winid
143143
end
144144

145145
local do_split = mode == "split" or mode == "vsplit"
@@ -164,7 +164,7 @@ function M.fn(mode, filename)
164164
local splitside = view.is_vertical() and "vsp" or "sp"
165165
vim.cmd(window_opts.split_command .. " " .. splitside)
166166
target_winid = api.nvim_get_current_win()
167-
lib.Tree.target_winid = target_winid
167+
lib.target_winid = target_winid
168168

169169
-- No need to split, as we created a new window.
170170
do_split = false

lua/nvim-tree/lib.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ local git = require'nvim-tree.git'
1010

1111
local first_init_done = false
1212

13-
local M = {}
13+
local M = {
14+
target_winid = nil,
15+
}
1416

1517
M.Tree = {
1618
nodes = {},
1719
cwd = nil,
18-
target_winid = nil,
1920
}
2021

2122
local function load_children(cwd, children, parent)
@@ -115,11 +116,11 @@ function M.set_target_win()
115116
local id = api.nvim_get_current_win()
116117
local tree_id = view.get_winnr()
117118
if tree_id and id == tree_id then
118-
M.Tree.target_winid = 0
119+
M.target_winid = 0
119120
return
120121
end
121122

122-
M.Tree.target_winid = id
123+
M.target_winid = id
123124
end
124125

125126
function M.open()

0 commit comments

Comments
 (0)