From 8b27fd4e613167db3f04c0ef25e61d52b8c5d494 Mon Sep 17 00:00:00 2001 From: kiyan Date: Sun, 6 Feb 2022 17:03:23 +0100 Subject: [PATCH] refacto: move target_winid outside of tree --- lua/nvim-tree/actions/open-file.lua | 10 +++++----- lua/nvim-tree/lib.lua | 9 +++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/nvim-tree/actions/open-file.lua b/lua/nvim-tree/actions/open-file.lua index 62852813..d93fb03d 100644 --- a/lua/nvim-tree/actions/open-file.lua +++ b/lua/nvim-tree/actions/open-file.lua @@ -95,8 +95,8 @@ local function open_file_in_tab(filename) else -- Switch window first to ensure new window doesn't inherit settings from -- NvimTree - if lib.Tree.target_winid > 0 and api.nvim_win_is_valid(lib.Tree.target_winid) then - api.nvim_set_current_win(lib.Tree.target_winid) + if lib.target_winid > 0 and api.nvim_win_is_valid(lib.target_winid) then + api.nvim_set_current_win(lib.target_winid) else vim.cmd("wincmd p") end @@ -133,13 +133,13 @@ function M.fn(mode, filename) local target_winid if vim.g.nvim_tree_disable_window_picker == 1 or mode == "edit_no_picker" then - target_winid = lib.Tree.target_winid + target_winid = lib.target_winid else target_winid = pick_window() end if target_winid == -1 then - target_winid = lib.Tree.target_winid + target_winid = lib.target_winid end local do_split = mode == "split" or mode == "vsplit" @@ -164,7 +164,7 @@ function M.fn(mode, filename) local splitside = view.is_vertical() and "vsp" or "sp" vim.cmd(window_opts.split_command .. " " .. splitside) target_winid = api.nvim_get_current_win() - lib.Tree.target_winid = target_winid + lib.target_winid = target_winid -- No need to split, as we created a new window. do_split = false diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 1a6e16ff..1c00f96f 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -10,12 +10,13 @@ local git = require'nvim-tree.git' local first_init_done = false -local M = {} +local M = { + target_winid = nil, +} M.Tree = { nodes = {}, cwd = nil, - target_winid = nil, } local function load_children(cwd, children, parent) @@ -115,11 +116,11 @@ function M.set_target_win() local id = api.nvim_get_current_win() local tree_id = view.get_winnr() if tree_id and id == tree_id then - M.Tree.target_winid = 0 + M.target_winid = 0 return end - M.Tree.target_winid = id + M.target_winid = id end function M.open()