refactor(#2826): remove unnecessary view members float, hide_root_folder; use explorer opts

This commit is contained in:
Alexander Courtis 2025-06-20 09:03:19 +10:00
parent de2ae0b06f
commit 414e576bc2
4 changed files with 13 additions and 17 deletions

View File

@ -18,7 +18,7 @@ local function close_windows(windows)
-- Prevent from closing when the win count equals 1 or 2, -- Prevent from closing when the win count equals 1 or 2,
-- where the win to remove could be the last opened. -- where the win to remove could be the last opened.
-- For details see #2503. -- For details see #2503.
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
return return
end end
@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
for _, buf in pairs(bufs) do for _, buf in pairs(bufs) do
if buf.name == absolute_path then if buf.name == absolute_path then
local tree_winnr = vim.api.nvim_get_current_win() local tree_winnr = vim.api.nvim_get_current_win()
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
vim.api.nvim_set_current_win(buf.windows[1]) vim.api.nvim_set_current_win(buf.windows[1])
vim.cmd(":bn") vim.cmd(":bn")
end end
vim.api.nvim_buf_delete(buf.bufnr, { force = true }) vim.api.nvim_buf_delete(buf.bufnr, { force = true })
if explorer and not explorer.view.float.quit_on_focus_loss then if explorer and not explorer.opts.view.float.quit_on_focus_loss then
vim.api.nvim_set_current_win(tree_winnr) vim.api.nvim_set_current_win(tree_winnr)
end end
if M.config.actions.remove_file.close_window then if M.config.actions.remove_file.close_window then

View File

@ -346,7 +346,7 @@ local function open_in_new_window(filename, mode)
end end
end end
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.view.float.enable then if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.opts.view.float.enable then
-- ignore "WinLeave" autocmd on preview -- ignore "WinLeave" autocmd on preview
-- because the registered "WinLeave" -- because the registered "WinLeave"
-- will kill the floating window immediately -- will kill the floating window immediately

View File

@ -61,7 +61,7 @@ local overlay_bufnr = 0
local overlay_winnr = 0 local overlay_winnr = 0
local function remove_overlay(self) local function remove_overlay(self)
if self.explorer.view.float.enable and self.explorer.view.float.quit_on_focus_loss then if self.explorer.opts.view.float.enable and self.explorer.opts.view.float.quit_on_focus_loss then
-- return to normal nvim-tree float behaviour when filter window is closed -- return to normal nvim-tree float behaviour when filter window is closed
vim.api.nvim_create_autocmd("WinLeave", { vim.api.nvim_create_autocmd("WinLeave", {
pattern = "NvimTree_*", pattern = "NvimTree_*",
@ -171,7 +171,7 @@ local function calculate_overlay_win_width(self)
end end
local function create_overlay(self) local function create_overlay(self)
if self.explorer.view.float.enable then if self.explorer.opts.view.float.enable then
-- don't close nvim-tree float when focus is changed to filter window -- don't close nvim-tree float when focus is changed to filter window
vim.api.nvim_clear_autocmds({ vim.api.nvim_clear_autocmds({
event = "WinLeave", event = "WinLeave",

View File

@ -11,11 +11,9 @@ local Class = require("nvim-tree.classic")
---@class (exact) View: Class ---@class (exact) View: Class
---@field live_filter table ---@field live_filter table
---@field side string ---@field side string
---@field float table
---@field private explorer Explorer ---@field private explorer Explorer
---@field private adaptive_size boolean ---@field private adaptive_size boolean
---@field private centralize_selection boolean ---@field private centralize_selection boolean
---@field private hide_root_folder boolean
---@field private winopts table ---@field private winopts table
---@field private height integer ---@field private height integer
---@field private preserve_window_proportions boolean ---@field private preserve_window_proportions boolean
@ -40,9 +38,7 @@ function View:new(args)
self.explorer = args.explorer self.explorer = args.explorer
self.adaptive_size = false self.adaptive_size = false
self.centralize_selection = self.explorer.opts.view.centralize_selection self.centralize_selection = self.explorer.opts.view.centralize_selection
self.float = self.explorer.opts.view.float
self.height = self.explorer.opts.view.height self.height = self.explorer.opts.view.height
self.hide_root_folder = self.explorer.opts.renderer.root_folder_label == false
self.preserve_window_proportions = self.explorer.opts.view.preserve_window_proportions self.preserve_window_proportions = self.explorer.opts.view.preserve_window_proportions
self.side = (self.explorer.opts.view.side == "right") and "right" or "left" self.side = (self.explorer.opts.view.side == "right") and "right" or "left"
self.live_filter = { prev_focused_node = nil, } self.live_filter = { prev_focused_node = nil, }
@ -217,16 +213,16 @@ end
---@private ---@private
---@return table ---@return table
function View:open_win_config() function View:open_win_config()
if type(self.float.open_win_config) == "function" then if type(self.explorer.opts.view.float.open_win_config) == "function" then
return self.float.open_win_config() return self.explorer.opts.view.float.open_win_config()
else else
return self.float.open_win_config return self.explorer.opts.view.float.open_win_config
end end
end end
---@private ---@private
function View:open_window() function View:open_window()
if self.float.enable then if self.explorer.opts.view.float.enable then
vim.api.nvim_open_win(0, true, self:open_win_config()) vim.api.nvim_open_win(0, true, self:open_win_config())
else else
vim.api.nvim_command("vsp") vim.api.nvim_command("vsp")
@ -405,9 +401,9 @@ end
---@param size string|number|nil ---@param size string|number|nil
function View:resize(size) function View:resize(size)
if self.float.enable and not self.adaptive_size then if self.explorer.opts.view.float.enable and not self.adaptive_size then
-- if the floating windows's adaptive size is not desired, then the -- if the floating windows's adaptive size is not desired, then the
-- float size should be defined in view.float.open_win_config -- float size should be defined in self.explorer.opts.view.float.open_win_config
return return
end end
@ -761,7 +757,7 @@ end
---@param cwd string|nil ---@param cwd string|nil
---@return boolean ---@return boolean
function View:is_root_folder_visible(cwd) function View:is_root_folder_visible(cwd)
return cwd ~= "/" and not self.hide_root_folder return cwd ~= "/" and self.explorer.opts.renderer.root_folder_label ~= false
end end
-- used on ColorScheme event -- used on ColorScheme event