Skip to content

Commit 414e576

Browse files
committed
refactor(#2826): remove unnecessary view members float, hide_root_folder; use explorer opts
1 parent de2ae0b commit 414e576

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

lua/nvim-tree/actions/fs/remove-file.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local function close_windows(windows)
1818
-- Prevent from closing when the win count equals 1 or 2,
1919
-- where the win to remove could be the last opened.
2020
-- For details see #2503.
21-
if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then
21+
if explorer and explorer.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
2222
return
2323
end
2424

@@ -36,12 +36,12 @@ local function clear_buffer(absolute_path)
3636
for _, buf in pairs(bufs) do
3737
if buf.name == absolute_path then
3838
local tree_winnr = vim.api.nvim_get_current_win()
39-
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.view.float.enable) then
39+
if buf.hidden == 0 and (#bufs > 1 or explorer and explorer.opts.view.float.enable) then
4040
vim.api.nvim_set_current_win(buf.windows[1])
4141
vim.cmd(":bn")
4242
end
4343
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
44-
if explorer and not explorer.view.float.quit_on_focus_loss then
44+
if explorer and not explorer.opts.view.float.quit_on_focus_loss then
4545
vim.api.nvim_set_current_win(tree_winnr)
4646
end
4747
if M.config.actions.remove_file.close_window then

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ local function open_in_new_window(filename, mode)
346346
end
347347
end
348348

349-
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.view.float.enable then
349+
if (mode == "preview" or mode == "preview_no_picker") and explorer and explorer.opts.view.float.enable then
350350
-- ignore "WinLeave" autocmd on preview
351351
-- because the registered "WinLeave"
352352
-- will kill the floating window immediately

lua/nvim-tree/explorer/live-filter.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ local overlay_bufnr = 0
6161
local overlay_winnr = 0
6262

6363
local function remove_overlay(self)
64-
if self.explorer.view.float.enable and self.explorer.view.float.quit_on_focus_loss then
64+
if self.explorer.opts.view.float.enable and self.explorer.opts.view.float.quit_on_focus_loss then
6565
-- return to normal nvim-tree float behaviour when filter window is closed
6666
vim.api.nvim_create_autocmd("WinLeave", {
6767
pattern = "NvimTree_*",
@@ -171,7 +171,7 @@ local function calculate_overlay_win_width(self)
171171
end
172172

173173
local function create_overlay(self)
174-
if self.explorer.view.float.enable then
174+
if self.explorer.opts.view.float.enable then
175175
-- don't close nvim-tree float when focus is changed to filter window
176176
vim.api.nvim_clear_autocmds({
177177
event = "WinLeave",

lua/nvim-tree/explorer/view.lua

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ local Class = require("nvim-tree.classic")
1111
---@class (exact) View: Class
1212
---@field live_filter table
1313
---@field side string
14-
---@field float table
1514
---@field private explorer Explorer
1615
---@field private adaptive_size boolean
1716
---@field private centralize_selection boolean
18-
---@field private hide_root_folder boolean
1917
---@field private winopts table
2018
---@field private height integer
2119
---@field private preserve_window_proportions boolean
@@ -40,9 +38,7 @@ function View:new(args)
4038
self.explorer = args.explorer
4139
self.adaptive_size = false
4240
self.centralize_selection = self.explorer.opts.view.centralize_selection
43-
self.float = self.explorer.opts.view.float
4441
self.height = self.explorer.opts.view.height
45-
self.hide_root_folder = self.explorer.opts.renderer.root_folder_label == false
4642
self.preserve_window_proportions = self.explorer.opts.view.preserve_window_proportions
4743
self.side = (self.explorer.opts.view.side == "right") and "right" or "left"
4844
self.live_filter = { prev_focused_node = nil, }
@@ -217,16 +213,16 @@ end
217213
---@private
218214
---@return table
219215
function View:open_win_config()
220-
if type(self.float.open_win_config) == "function" then
221-
return self.float.open_win_config()
216+
if type(self.explorer.opts.view.float.open_win_config) == "function" then
217+
return self.explorer.opts.view.float.open_win_config()
222218
else
223-
return self.float.open_win_config
219+
return self.explorer.opts.view.float.open_win_config
224220
end
225221
end
226222

227223
---@private
228224
function View:open_window()
229-
if self.float.enable then
225+
if self.explorer.opts.view.float.enable then
230226
vim.api.nvim_open_win(0, true, self:open_win_config())
231227
else
232228
vim.api.nvim_command("vsp")
@@ -405,9 +401,9 @@ end
405401

406402
---@param size string|number|nil
407403
function View:resize(size)
408-
if self.float.enable and not self.adaptive_size then
404+
if self.explorer.opts.view.float.enable and not self.adaptive_size then
409405
-- if the floating windows's adaptive size is not desired, then the
410-
-- float size should be defined in view.float.open_win_config
406+
-- float size should be defined in self.explorer.opts.view.float.open_win_config
411407
return
412408
end
413409

@@ -761,7 +757,7 @@ end
761757
---@param cwd string|nil
762758
---@return boolean
763759
function View:is_root_folder_visible(cwd)
764-
return cwd ~= "/" and not self.hide_root_folder
760+
return cwd ~= "/" and self.explorer.opts.renderer.root_folder_label ~= false
765761
end
766762

767763
-- used on ColorScheme event

0 commit comments

Comments
 (0)