From fc81249d4f5db207f65212e1e206da28a4f0b541 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 16 Jun 2025 13:42:56 +1000 Subject: [PATCH] refactor(#2826): rename View to Window --- lua/nvim-tree.lua | 10 +-- lua/nvim-tree/actions/finders/find-file.lua | 6 +- lua/nvim-tree/actions/fs/remove-file.lua | 6 +- lua/nvim-tree/actions/moves/item.lua | 8 +- lua/nvim-tree/actions/moves/parent.lua | 4 +- lua/nvim-tree/actions/node/open-file.lua | 20 ++--- lua/nvim-tree/actions/tree/find-file.lua | 4 +- lua/nvim-tree/actions/tree/open.lua | 4 +- lua/nvim-tree/actions/tree/resize.lua | 14 +-- lua/nvim-tree/actions/tree/toggle.lua | 4 +- lua/nvim-tree/api.lua | 4 +- lua/nvim-tree/commands.lua | 2 +- lua/nvim-tree/core.lua | 2 +- lua/nvim-tree/diagnostics.lua | 2 +- lua/nvim-tree/explorer/init.lua | 20 ++--- lua/nvim-tree/explorer/live-filter.lua | 6 +- .../explorer/{view.lua => window.lua} | 88 +++++++++---------- lua/nvim-tree/lib.lua | 14 +-- lua/nvim-tree/renderer/builder.lua | 2 +- lua/nvim-tree/renderer/init.lua | 10 +-- lua/nvim-tree/utils.lua | 6 +- 21 files changed, 118 insertions(+), 118 deletions(-) rename lua/nvim-tree/explorer/{view.lua => window.lua} (92%) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 449ac2b7..80317e15 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -74,7 +74,7 @@ end function M.tab_enter() local explorer = core.get_explorer() - if explorer and explorer.view:is_visible({ any_tabpage = true }) then + if explorer and explorer.window:is_visible({ any_tabpage = true }) then local bufname = vim.api.nvim_buf_get_name(0) local ft @@ -89,7 +89,7 @@ function M.tab_enter() return end end - explorer.view:open({ focus_tree = false }) + explorer.window:open({ focus_tree = false }) explorer.renderer:draw() end @@ -97,7 +97,7 @@ end function M.open_on_directory() local explorer = core.get_explorer() - local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.view:is_visible() + local should_proceed = _config.hijack_directories.auto_open or explorer and explorer.window:is_visible() if not should_proceed then return end @@ -667,8 +667,8 @@ end function M.purge_all_state() local explorer = core.get_explorer() if explorer then - explorer.view:close_all_tabs() - explorer.view:abandon_all_windows() + explorer.window:close_all_tabs() + explorer.window:abandon_all_windows() require("nvim-tree.git").purge_state() explorer:destroy() core.reset_explorer() diff --git a/lua/nvim-tree/actions/finders/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua index 2ea494fd..aa8274e2 100644 --- a/lua/nvim-tree/actions/finders/find-file.lua +++ b/lua/nvim-tree/actions/finders/find-file.lua @@ -13,7 +13,7 @@ local running = {} ---@param path string relative or absolute function M.fn(path) local explorer = core.get_explorer() - if not explorer or not explorer.view:is_visible() then + if not explorer or not explorer.window:is_visible() then return end @@ -83,9 +83,9 @@ function M.fn(path) end) :iterate() - if found and explorer.view:is_visible() then + if found and explorer.window:is_visible() then explorer.renderer:draw() - explorer.view:set_cursor({ line, 0 }) + explorer.window:set_cursor({ line, 0 }) end running[path_real] = false diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index fd71ae6a..0c5fa362 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -18,7 +18,7 @@ local function close_windows(windows) -- Prevent from closing when the win count equals 1 or 2, -- where the win to remove could be the last opened. -- For details see #2503. - if explorer and explorer.view.float.enable and #vim.api.nvim_list_wins() < 3 then + if explorer and explorer.window.float.enable and #vim.api.nvim_list_wins() < 3 then return end @@ -36,12 +36,12 @@ local function clear_buffer(absolute_path) for _, buf in pairs(bufs) do if buf.name == absolute_path then 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.window.float.enable) then vim.api.nvim_set_current_win(buf.windows[1]) vim.cmd(":bn") end 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.window.float.quit_on_focus_loss then vim.api.nvim_set_current_win(tree_winnr) end if M.config.actions.remove_file.close_window then diff --git a/lua/nvim-tree/actions/moves/item.lua b/lua/nvim-tree/actions/moves/item.lua index 599a8053..90d6616b 100644 --- a/lua/nvim-tree/actions/moves/item.lua +++ b/lua/nvim-tree/actions/moves/item.lua @@ -66,9 +66,9 @@ local function move(explorer, where, what, skip_gitignored) end if nex then - explorer.view:set_cursor({ nex, 0 }) + explorer.window:set_cursor({ nex, 0 }) elseif vim.o.wrapscan and first then - explorer.view:set_cursor({ first, 0 }) + explorer.window:set_cursor({ first, 0 }) end end @@ -188,13 +188,13 @@ local function move_prev_recursive(explorer, what, skip_gitignored) -- 4.3) if node_init.name == ".." then -- root node - explorer.view:set_cursor({ 1, 0 }) -- move to root node (position 1) + explorer.window:set_cursor({ 1, 0 }) -- move to root node (position 1) else local node_init_line = utils.find_node_line(node_init) if node_init_line < 0 then return end - explorer.view:set_cursor({ node_init_line, 0 }) + explorer.window:set_cursor({ node_init_line, 0 }) end -- 4.4) diff --git a/lua/nvim-tree/actions/moves/parent.lua b/lua/nvim-tree/actions/moves/parent.lua index fab1a440..438a9abe 100644 --- a/lua/nvim-tree/actions/moves/parent.lua +++ b/lua/nvim-tree/actions/moves/parent.lua @@ -24,7 +24,7 @@ function M.fn(should_close) local parent = (node:get_parent_of_group() or node).parent if not parent or not parent.parent then - node.explorer.view:set_cursor({ 1, 0 }) + node.explorer.window:set_cursor({ 1, 0 }) return end @@ -32,7 +32,7 @@ function M.fn(should_close) return n.absolute_path == parent.absolute_path end) - node.explorer.view:set_cursor({ line + 1, 0 }) + node.explorer.window:set_cursor({ line + 1, 0 }) if should_close then parent.open = false parent.explorer.renderer:draw() diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index 99594520..ddc78a8b 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -22,7 +22,7 @@ local function usable_win_ids() local explorer = core.get_explorer() local tabpage = vim.api.nvim_get_current_tabpage() local win_ids = vim.api.nvim_tabpage_list_wins(tabpage) - local tree_winid = explorer and explorer.view:get_winnr(tabpage) + local tree_winid = explorer and explorer.window:get_winnr(tabpage) return vim.tbl_filter(function(id) local bufid = vim.api.nvim_win_get_buf(id) @@ -190,7 +190,7 @@ local function open_file_in_tab(filename) if M.quit_on_open then local explorer = core.get_explorer() if explorer then - explorer.view:close() + explorer.window:close() end end if M.relative_path then @@ -203,7 +203,7 @@ local function drop(filename) if M.quit_on_open then local explorer = core.get_explorer() if explorer then - explorer.view:close() + explorer.window:close() end end if M.relative_path then @@ -216,7 +216,7 @@ local function tab_drop(filename) if M.quit_on_open then local explorer = core.get_explorer() if explorer then - explorer.view:close() + explorer.window:close() end end if M.relative_path then @@ -240,7 +240,7 @@ local function on_preview(buf_loaded) end local explorer = core.get_explorer() if explorer then - explorer.view:focus() + explorer.window:focus() end end @@ -312,7 +312,7 @@ local function open_in_new_window(filename, mode) local create_new_window = #win_ids == 1 -- This implies that the nvim-tree window is the only one local new_window_side = "belowright" - if explorer and (explorer.view.side == "right") then + if explorer and (explorer.window.side == "right") then new_window_side = "aboveleft" end @@ -346,7 +346,7 @@ local function open_in_new_window(filename, mode) 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.window.float.enable then -- ignore "WinLeave" autocmd on preview -- because the registered "WinLeave" -- will kill the floating window immediately @@ -389,7 +389,7 @@ local function edit_in_current_buf(filename) local explorer = core.get_explorer() if explorer then - explorer.view:abandon_current_window() + explorer.window:abandon_current_window() end if M.relative_path then @@ -439,7 +439,7 @@ function M.fn(mode, filename) end if M.resize_window and explorer then - explorer.view:resize() + explorer.window:resize() end if mode == "preview" or mode == "preview_no_picker" then @@ -447,7 +447,7 @@ function M.fn(mode, filename) end if M.quit_on_open and explorer then - explorer.view:close() + explorer.window:close() end end diff --git a/lua/nvim-tree/actions/tree/find-file.lua b/lua/nvim-tree/actions/tree/find-file.lua index 73d1df3c..3e2faabb 100644 --- a/lua/nvim-tree/actions/tree/find-file.lua +++ b/lua/nvim-tree/actions/tree/find-file.lua @@ -41,11 +41,11 @@ function M.fn(opts) end local explorer = core.get_explorer() - if explorer and explorer.view:is_visible() then + if explorer and explorer.window:is_visible() then -- focus if opts.focus then lib.set_target_win() - explorer.view:focus() + explorer.window:focus() end elseif opts.open then -- open diff --git a/lua/nvim-tree/actions/tree/open.lua b/lua/nvim-tree/actions/tree/open.lua index 17e2c581..31592741 100644 --- a/lua/nvim-tree/actions/tree/open.lua +++ b/lua/nvim-tree/actions/tree/open.lua @@ -25,10 +25,10 @@ function M.fn(opts) local explorer = core.get_explorer() - if explorer and explorer.view:is_visible() then + if explorer and explorer.window:is_visible() then -- focus lib.set_target_win() - explorer.view:focus() + explorer.window:focus() else -- open lib.open({ diff --git a/lua/nvim-tree/actions/tree/resize.lua b/lua/nvim-tree/actions/tree/resize.lua index 48f09088..7c88cb91 100644 --- a/lua/nvim-tree/actions/tree/resize.lua +++ b/lua/nvim-tree/actions/tree/resize.lua @@ -12,8 +12,8 @@ function M.fn(opts) if opts == nil then -- reset to config values - explorer.view:configure_width() - explorer.view:resize() + explorer.window:configure_width() + explorer.window:resize() return end @@ -21,19 +21,19 @@ function M.fn(opts) local width_cfg = options.width if width_cfg ~= nil then - explorer.view:configure_width(width_cfg) - explorer.view:resize() + explorer.window:configure_width(width_cfg) + explorer.window:resize() return end - if not explorer.view:is_width_determined() then + if not explorer.window:is_width_determined() then -- {absolute} and {relative} do nothing when {width} is a function. return end local absolute = options.absolute if type(absolute) == "number" then - explorer.view:resize(absolute) + explorer.window:resize(absolute) return end @@ -44,7 +44,7 @@ function M.fn(opts) relative_size = "+" .. relative_size end - explorer.view:resize(relative_size) + explorer.window:resize(relative_size) return end end diff --git a/lua/nvim-tree/actions/tree/toggle.lua b/lua/nvim-tree/actions/tree/toggle.lua index fb976cfb..79691dcb 100644 --- a/lua/nvim-tree/actions/tree/toggle.lua +++ b/lua/nvim-tree/actions/tree/toggle.lua @@ -42,9 +42,9 @@ function M.fn(opts, no_focus, cwd, bang) opts.path = nil end - if explorer and explorer.view:is_visible() then + if explorer and explorer.window:is_visible() then -- close - explorer.view:close() + explorer.window:close() else -- open lib.open({ diff --git a/lua/nvim-tree/api.lua b/lua/nvim-tree/api.lua index 3f70df2c..e204c048 100644 --- a/lua/nvim-tree/api.lua +++ b/lua/nvim-tree/api.lua @@ -247,7 +247,7 @@ local function edit(mode, node, edit_opts) local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place" if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then if explorer then - explorer.view:close(cur_tabpage) + explorer.window:close(cur_tabpage) end end @@ -259,7 +259,7 @@ local function edit(mode, node, edit_opts) vim.cmd(":tabprev") end if explorer then - explorer.view:focus() + explorer.window:focus() end end end diff --git a/lua/nvim-tree/commands.lua b/lua/nvim-tree/commands.lua index 88ac3e1e..afac3e25 100644 --- a/lua/nvim-tree/commands.lua +++ b/lua/nvim-tree/commands.lua @@ -113,7 +113,7 @@ local CMDS = { command = function(c) local explorer = core.get_explorer() if explorer then - explorer.view:resize(c.args) + explorer.window:resize(c.args) end end, }, diff --git a/lua/nvim-tree/core.lua b/lua/nvim-tree/core.lua index fe9125e6..5db9e0f2 100644 --- a/lua/nvim-tree/core.lua +++ b/lua/nvim-tree/core.lua @@ -54,7 +54,7 @@ end ---@return integer function M.get_nodes_starting_line() local offset = 1 - if TreeExplorer and TreeExplorer.view:is_root_folder_visible(M.get_cwd()) then + if TreeExplorer and TreeExplorer.window:is_root_folder_visible(M.get_cwd()) then offset = offset + 1 end if TreeExplorer and TreeExplorer.live_filter.filter then diff --git a/lua/nvim-tree/diagnostics.lua b/lua/nvim-tree/diagnostics.lua index e6484caf..97910184 100644 --- a/lua/nvim-tree/diagnostics.lua +++ b/lua/nvim-tree/diagnostics.lua @@ -185,7 +185,7 @@ function M.update_coc() local bufnr if explorer then - bufnr = explorer.view:get_bufnr() + bufnr = explorer.window:get_bufnr() end local should_draw = bufnr and vim.api.nvim_buf_is_valid(bufnr) and vim.api.nvim_buf_is_loaded(bufnr) diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index 71b7b4e1..4c12ff2f 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -19,7 +19,7 @@ local LiveFilter = require("nvim-tree.explorer.live-filter") local Sorter = require("nvim-tree.explorer.sorter") local Clipboard = require("nvim-tree.actions.fs.clipboard") local Renderer = require("nvim-tree.renderer") -local View = require("nvim-tree.explorer.view") +local Window = require("nvim-tree.explorer.window") local FILTER_REASON = require("nvim-tree.enum").FILTER_REASON @@ -35,7 +35,7 @@ local config ---@field sorters Sorter ---@field marks Marks ---@field clipboard Clipboard ----@field view View +---@field window Window local Explorer = RootNode:extend() ---@class Explorer @@ -67,7 +67,7 @@ function Explorer:new(args) self.live_filter = LiveFilter({ explorer = self }) self.marks = Marks({ explorer = self }) self.clipboard = Clipboard({ explorer = self }) - self.view = View({ explorer = self }) + self.window = Window({ explorer = self }) self:create_autocmds() @@ -88,7 +88,7 @@ function Explorer:create_autocmds() group = self.augroup_id, callback = function() appearance.setup() - self.view:reset_winhl() + self.window:reset_winhl() self.renderer:draw() end, }) @@ -99,7 +99,7 @@ function Explorer:create_autocmds() pattern = "NvimTree_*", callback = function() if utils.is_nvim_tree_buf(0) then - self.view:close() + self.window:close() end end, }) @@ -166,9 +166,9 @@ function Explorer:create_autocmds() return end if self.opts.actions.open_file.eject then - self.view:prevent_buffer_override() + self.window:prevent_buffer_override() else - self.view:abandon_current_window() + self.window:abandon_current_window() end end, }) @@ -518,7 +518,7 @@ function Explorer:reload_explorer() local projects = git.reload_all_projects() self:refresh_nodes(projects) - if self.view:is_visible() then + if self.window:is_visible() then self.renderer:draw() end event_running = false @@ -540,7 +540,7 @@ end ---nil on no explorer or invalid view win ---@return integer[]|nil function Explorer:get_cursor_position() - local winnr = self.view:get_winnr() + local winnr = self.window:get_winnr() if not winnr or not vim.api.nvim_win_is_valid(winnr) then return end @@ -555,7 +555,7 @@ function Explorer:get_node_at_cursor() return end - if cursor[1] == 1 and self.view:is_root_folder_visible(core.get_cwd()) then + if cursor[1] == 1 and self.window:is_root_folder_visible(core.get_cwd()) then return self end diff --git a/lua/nvim-tree/explorer/live-filter.lua b/lua/nvim-tree/explorer/live-filter.lua index 704945e1..c5b5770a 100644 --- a/lua/nvim-tree/explorer/live-filter.lua +++ b/lua/nvim-tree/explorer/live-filter.lua @@ -199,13 +199,13 @@ local function create_overlay(self) end function LiveFilter:start_filtering() - self.explorer.view.live_filter.prev_focused_node = self.explorer:get_node_at_cursor() + self.explorer.window.live_filter.prev_focused_node = self.explorer:get_node_at_cursor() self.filter = self.filter or "" self.explorer.renderer:draw() local row = require("nvim-tree.core").get_nodes_starting_line() - 1 local col = #self.prefix > 0 and #self.prefix - 1 or 1 - self.explorer.view:set_cursor({ row, col }) + self.explorer.window:set_cursor({ row, col }) -- needs scheduling to let the cursor move before initializing the window vim.schedule(function() return create_overlay(self) @@ -214,7 +214,7 @@ end function LiveFilter:clear_filter() local node = self.explorer:get_node_at_cursor() - local last_node = self.explorer.view.live_filter.prev_focused_node + local last_node = self.explorer.window.live_filter.prev_focused_node self.filter = nil reset_filter(self) diff --git a/lua/nvim-tree/explorer/view.lua b/lua/nvim-tree/explorer/window.lua similarity index 92% rename from lua/nvim-tree/explorer/view.lua rename to lua/nvim-tree/explorer/window.lua index ec7ea2d7..fcf497c7 100644 --- a/lua/nvim-tree/explorer/view.lua +++ b/lua/nvim-tree/explorer/window.lua @@ -23,7 +23,7 @@ M.View = { tabpages = {} } ----@class (exact) View: Class +---@class (exact) Window: Class ---@field live_filter table ---@field side string ---@field float table @@ -39,18 +39,18 @@ M.View = { ---@field private width (fun():integer)|integer|string ---@field private max_width integer ---@field private padding integer -local View = Class:extend() +local Window = Class:extend() ----@class View ----@overload fun(args: ViewArgs): View +---@class Window +---@overload fun(args: WindowArgs): Window ----@class (exact) ViewArgs +---@class (exact) WindowArgs ---@field explorer Explorer ---@protected ----@param args ViewArgs -function View:new(args) - args.explorer:log_lifecycle("View:new") +---@param args WindowArgs +function Window:new(args) + args.explorer:log_lifecycle("Window:new") self.explorer = args.explorer self.adaptive_size = false @@ -111,7 +111,7 @@ local BUFFER_OPTIONS = { ---@private ---@param bufnr integer ---@return boolean -function View:matches_bufnr(bufnr) +function Window:matches_bufnr(bufnr) for _, b in pairs(BUFNR_PER_TAB) do if b == bufnr then return true @@ -121,7 +121,7 @@ function View:matches_bufnr(bufnr) end ---@private -function View:wipe_rogue_buffer() +function Window:wipe_rogue_buffer() for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do if not self:matches_bufnr(bufnr) and utils.is_nvim_tree_buf(bufnr) then pcall(vim.api.nvim_buf_delete, bufnr, { force = true }) @@ -131,7 +131,7 @@ end ---@private ---@param bufnr integer|false|nil -function View:create_buffer(bufnr) +function Window:create_buffer(bufnr) self:wipe_rogue_buffer() local tab = vim.api.nvim_get_current_tabpage() @@ -151,7 +151,7 @@ end ---@private ---@param size (fun():integer)|integer|string ---@return integer -function View:get_size(size) +function Window:get_size(size) if type(size) == "number" then return size elseif type(size) == "function" then @@ -164,7 +164,7 @@ end ---@param size (fun():integer)|integer|nil ---@return integer -function View:get_width(size) +function Window:get_width(size) if size then return self:get_size(size) else @@ -180,13 +180,13 @@ local move_tbl = { -- setup_tabpage sets up the initial state of a tab ---@private ---@param tabpage integer -function View:setup_tabpage(tabpage) +function Window:setup_tabpage(tabpage) local winnr = vim.api.nvim_get_current_win() M.View.tabpages[tabpage] = vim.tbl_extend("force", M.View.tabpages[tabpage] or tabinitial, { winnr = winnr }) end ---@private -function View:set_window_options_and_buffer() +function Window:set_window_options_and_buffer() pcall(vim.api.nvim_command, "buffer " .. self:get_bufnr()) if vim.fn.has("nvim-0.10") == 1 then @@ -214,7 +214,7 @@ end ---@private ---@return table -function View:open_win_config() +function Window:open_win_config() if type(self.float.open_win_config) == "function" then return self.float.open_win_config() else @@ -223,7 +223,7 @@ function View:open_win_config() end ---@private -function View:open_window() +function Window:open_window() if self.float.enable then vim.api.nvim_open_win(0, true, self:open_win_config()) else @@ -268,14 +268,14 @@ end ---save_tab_state saves any state that should be preserved across redraws. ---@private ---@param tabnr integer -function View:save_tab_state(tabnr) +function Window:save_tab_state(tabnr) local tabpage = tabnr or vim.api.nvim_get_current_tabpage() self.cursors[tabpage] = vim.api.nvim_win_get_cursor(self:get_winnr(tabpage) or 0) end ---@private ---@param tabpage integer -function View:close_internal(tabpage) +function Window:close_internal(tabpage) if not self:is_visible({ tabpage = tabpage }) then return end @@ -301,18 +301,18 @@ function View:close_internal(tabpage) end end -function View:close_this_tab_only() +function Window:close_this_tab_only() self:close_internal(vim.api.nvim_get_current_tabpage()) end -function View:close_all_tabs() +function Window:close_all_tabs() for tabpage, _ in pairs(M.View.tabpages) do self:close_internal(tabpage) end end ---@param tabpage integer|nil -function View:close(tabpage) +function Window:close(tabpage) if self.explorer.opts.tab.sync.close then self:close_all_tabs() elseif tabpage then @@ -323,7 +323,7 @@ function View:close(tabpage) end ---@param options table|nil -function View:open(options) +function Window:open(options) if self:is_visible() then return end @@ -345,7 +345,7 @@ function View:open(options) end ---@private -function View:grow() +function Window:grow() local starts_at = self:is_root_folder_visible(require("nvim-tree.core").get_cwd()) and 1 or 0 local lines = vim.api.nvim_buf_get_lines(self:get_bufnr(), starts_at, -1, false) -- number of columns of right-padding to indicate end of path @@ -384,14 +384,14 @@ function View:grow() self:resize(resizing_width + padding) end -function View:grow_from_content() +function Window:grow_from_content() if self.adaptive_size then self:grow() end end ---@param size string|number|nil -function View:resize(size) +function Window:resize(size) if self.float.enable and not self.adaptive_size then -- if the floating windows's adaptive size is not desired, then the -- float size should be defined in view.float.open_win_config @@ -436,21 +436,21 @@ function View:resize(size) end ---@private -function View:reposition_window() +function Window:reposition_window() local move_to = move_tbl[self.side] vim.api.nvim_command("wincmd " .. move_to) self:resize() end ---@private -function View:set_current_win() +function Window:set_current_win() local current_tab = vim.api.nvim_get_current_tabpage() M.View.tabpages[current_tab].winnr = vim.api.nvim_get_current_win() end ---Open the tree in the a window ---@param opts OpenInWinOpts|nil -function View:open_in_win(opts) +function Window:open_in_win(opts) opts = opts or { hijack_current_buf = true, resize = true } events._dispatch_on_tree_pre_open() if opts.winid and vim.api.nvim_win_is_valid(opts.winid) then @@ -467,7 +467,7 @@ function View:open_in_win(opts) events._dispatch_on_tree_open() end -function View:abandon_current_window() +function Window:abandon_current_window() local tab = vim.api.nvim_get_current_tabpage() BUFNR_PER_TAB[tab] = nil if M.View.tabpages[tab] then @@ -475,7 +475,7 @@ function View:abandon_current_window() end end -function View:abandon_all_windows() +function Window:abandon_all_windows() for tab, _ in pairs(vim.api.nvim_list_tabpages()) do BUFNR_PER_TAB[tab] = nil if M.View.tabpages[tab] then @@ -486,7 +486,7 @@ end ---@param opts table|nil ---@return boolean -function View:is_visible(opts) +function Window:is_visible(opts) if opts and opts.tabpage then if M.View.tabpages[opts.tabpage] == nil then return false @@ -508,7 +508,7 @@ function View:is_visible(opts) end ---@param opts table|nil -function View:set_cursor(opts) +function Window:set_cursor(opts) if self:is_visible() then pcall(vim.api.nvim_win_set_cursor, self:get_winnr(), opts) end @@ -516,7 +516,7 @@ end ---@param winnr number|nil ---@param open_if_closed boolean|nil -function View:focus(winnr, open_if_closed) +function Window:focus(winnr, open_if_closed) local wnr = winnr or self:get_winnr() if vim.api.nvim_win_get_tabpage(wnr or 0) ~= vim.api.nvim_win_get_tabpage(0) then @@ -535,7 +535,7 @@ end --- Retrieve the winid of the open tree. ---@param opts ApiTreeWinIdOpts|nil ---@return number|nil winid unlike get_winnr(), this returns nil if the nvim-tree window is not visible -function View:winid(opts) +function Window:winid(opts) local tabpage = opts and opts.tabpage if tabpage == 0 then tabpage = vim.api.nvim_get_current_tabpage() @@ -548,7 +548,7 @@ function View:winid(opts) end --- Restores the state of a NvimTree window if it was initialized before. -function View:restore_tab_state() +function Window:restore_tab_state() local tabpage = vim.api.nvim_get_current_tabpage() self:set_cursor(self.cursors[tabpage]) end @@ -556,7 +556,7 @@ end --- Returns the window number for nvim-tree within the tabpage specified ---@param tabpage number|nil (optional) the number of the chosen tabpage. Defaults to current tabpage. ---@return number|nil -function View:get_winnr(tabpage) +function Window:get_winnr(tabpage) tabpage = tabpage or vim.api.nvim_get_current_tabpage() local tabinfo = M.View.tabpages[tabpage] if tabinfo and tabinfo.winnr and vim.api.nvim_win_is_valid(tabinfo.winnr) then @@ -566,11 +566,11 @@ end --- Returns the current nvim tree bufnr ---@return number -function View:get_bufnr() +function Window:get_bufnr() return BUFNR_PER_TAB[vim.api.nvim_get_current_tabpage()] end -function View:prevent_buffer_override() +function Window:prevent_buffer_override() local view_winnr = self:get_winnr() local view_bufnr = self:get_bufnr() @@ -620,12 +620,12 @@ end ---@param cwd string|nil ---@return boolean -function View:is_root_folder_visible(cwd) +function Window:is_root_folder_visible(cwd) return cwd ~= "/" and not self.hide_root_folder end -- used on ColorScheme event -function View:reset_winhl() +function Window:reset_winhl() local winnr = self:get_winnr() if winnr and vim.api.nvim_win_is_valid(winnr) then vim.wo[self:get_winnr()].winhl = appearance.WIN_HL @@ -634,13 +634,13 @@ end ---Check if width determined or calculated on-fly ---@return boolean -function View:is_width_determined() +function Window:is_width_determined() return type(self.width) ~= "function" end ---Configure width-related config ---@param width string|function|number|table|nil -function View:configure_width(width) +function Window:configure_width(width) if type(width) == "table" then self.adaptive_size = true self.width = width.min or DEFAULT_MIN_WIDTH @@ -660,4 +660,4 @@ function View:configure_width(width) end end -return View +return Window diff --git a/lua/nvim-tree/lib.lua b/lua/nvim-tree/lib.lua index 47930758..b390ec55 100644 --- a/lua/nvim-tree/lib.lua +++ b/lua/nvim-tree/lib.lua @@ -15,7 +15,7 @@ function M.set_target_win() local id = vim.api.nvim_get_current_win() - if explorer and id == explorer.view:get_winnr() then + if explorer and id == explorer.window:get_winnr() then M.target_winid = 0 return end @@ -36,7 +36,7 @@ local function open_view_and_draw() local cwd = vim.fn.getcwd() if explorer then - explorer.view:open() + explorer.window:open() end handle_buf_cwd(cwd) @@ -117,18 +117,18 @@ function M.open(opts) if should_hijack_current_buf() then if explorer then - explorer.view:close_this_tab_only() - explorer.view:open_in_win() + explorer.window:close_this_tab_only() + explorer.window:open_in_win() explorer.renderer:draw() end elseif opts.winid then if explorer then - explorer.view:open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid }) + explorer.window:open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid }) explorer.renderer:draw() end elseif opts.current_window then if explorer then - explorer.view:open_in_win({ hijack_current_buf = false, resize = false }) + explorer.window:open_in_win({ hijack_current_buf = false, resize = false }) explorer.renderer:draw() end else @@ -136,7 +136,7 @@ function M.open(opts) end if explorer then - explorer.view:restore_tab_state() + explorer.window:restore_tab_state() end end diff --git a/lua/nvim-tree/renderer/builder.lua b/lua/nvim-tree/renderer/builder.lua index d2727f3f..a2f8964c 100644 --- a/lua/nvim-tree/renderer/builder.lua +++ b/lua/nvim-tree/renderer/builder.lua @@ -378,7 +378,7 @@ end ---@private function Builder:build_header() - if self.explorer.view:is_root_folder_visible(self.explorer.absolute_path) then + if self.explorer.window:is_root_folder_visible(self.explorer.absolute_path) then local root_name = self:format_root_name(self.explorer.opts.renderer.root_folder_label) table.insert(self.lines, root_name) self:insert_highlight({ "NvimTreeRootFolder" }, 0, string.len(root_name)) diff --git a/lua/nvim-tree/renderer/init.lua b/lua/nvim-tree/renderer/init.lua index ff66f041..2e3848a7 100644 --- a/lua/nvim-tree/renderer/init.lua +++ b/lua/nvim-tree/renderer/init.lua @@ -97,28 +97,28 @@ function Renderer:render_hl(bufnr, hl_range_args) end function Renderer:draw() - local bufnr = self.explorer.view:get_bufnr() + local bufnr = self.explorer.window:get_bufnr() if not bufnr or not vim.api.nvim_buf_is_loaded(bufnr) then return end local profile = log.profile_start("draw") - local cursor = vim.api.nvim_win_get_cursor(self.explorer.view:get_winnr() or 0) + local cursor = vim.api.nvim_win_get_cursor(self.explorer.window:get_winnr() or 0) local builder = Builder(self.explorer):build() self:_draw(bufnr, builder.lines, builder.hl_range_args, builder.signs, builder.extmarks, builder.virtual_lines) if cursor and #builder.lines >= cursor[1] then - vim.api.nvim_win_set_cursor(self.explorer.view:get_winnr() or 0, cursor) + vim.api.nvim_win_set_cursor(self.explorer.window:get_winnr() or 0, cursor) end - self.explorer.view:grow_from_content() + self.explorer.window:grow_from_content() log.profile_end(profile) - events._dispatch_on_tree_rendered(bufnr, self.explorer.view:get_winnr()) + events._dispatch_on_tree_rendered(bufnr, self.explorer.window:get_winnr()) end return Renderer diff --git a/lua/nvim-tree/utils.lua b/lua/nvim-tree/utils.lua index e33aaaf1..87063a45 100644 --- a/lua/nvim-tree/utils.lua +++ b/lua/nvim-tree/utils.lua @@ -145,7 +145,7 @@ function M.find_node(nodes, fn) :iterate() if node then - if not node.explorer.view:is_root_folder_visible() then + if not node.explorer.window:is_root_folder_visible() then i = i - 1 end if node.explorer.live_filter.filter then @@ -545,7 +545,7 @@ function M.focus_file(path) end) local explorer = require("nvim-tree.core").get_explorer() if explorer then - explorer.view:set_cursor({ i + 1, 1 }) + explorer.window:set_cursor({ i + 1, 1 }) end end @@ -566,7 +566,7 @@ function M.focus_node_or_parent(node) end) if found_node or node.parent == nil then - explorer.view:set_cursor({ i + 1, 1 }) + explorer.window:set_cursor({ i + 1, 1 }) break end