Skip to content

refactor(#2826): remove view globals #3156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6e7ce87
refactor(#2826): fuller error messages
alex-courtis Jun 19, 2025
b7e9789
refactor(#2826): winnr->winid in view/globals, remove redundant get_w…
alex-courtis Jun 19, 2025
d6cd465
refactor(#2826): winnr->winid consistently
alex-courtis Jun 19, 2025
de2ae0b
refactor(#2826): consistent use of buffer registry, tidy, add todos
alex-courtis Jun 19, 2025
414e576
refactor(#2826): remove unnecessary view members float, hide_root_fol…
alex-courtis Jun 19, 2025
f1e9d51
refactor(#2826): remove unused view members centralize_selection and …
alex-courtis Jun 19, 2025
5fbd674
refactor(#2826): remove unused view member height
alex-courtis Jun 19, 2025
3615c7d
refactor(#2826): temporarily reuse BUFNR_PER_TAB in view constructor
alex-courtis Jun 19, 2025
09ec00c
refactor(#2826): get_winid returns new after consistency check
alex-courtis Jun 20, 2025
83fdff7
refactor(#2826): globals.TABPAGES -> WINID_PER_TAB
alex-courtis Jun 20, 2025
e875f15
refactor(#2826): consistent naming of tabid
alex-courtis Jun 20, 2025
d72f85f
refactor(#2826): more consistency checking
alex-courtis Jun 20, 2025
4d6c423
refactor(#2826): more consistency checking
alex-courtis Jun 20, 2025
d84dfad
refactor(#2826): move global CURSORS to view member
alex-courtis Jun 20, 2025
82cc80f
Revert "refactor(#2826): move global CURSORS to view member"
alex-courtis Jun 20, 2025
51b269d
refactor(#2826): move global CURSORS to view member
alex-courtis Jun 20, 2025
0830436
refactor(#2826): consistency check returns new
alex-courtis Jun 20, 2025
fee19f4
Merge branch 'master' into 2826-remove-view-globals
alex-courtis Jun 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.view:is_visible({ any_tabpage = true }, "nvim-tree.tab_enter") then
local bufname = vim.api.nvim_buf_get_name(0)

local ft
Expand All @@ -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.view:is_visible(nil, "nvim-tree.open_on_directory")
if not should_proceed then
return
end
Expand Down Expand Up @@ -669,7 +669,7 @@ function M.purge_all_state()
local explorer = core.get_explorer()
if explorer then
explorer.view:close_all_tabs()
explorer.view:abandon_all_windows("purge_all_state")
explorer.view:abandon_all_windows()
require("nvim-tree.git").purge_state()
explorer:destroy()
core.reset_explorer()
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/actions/finders/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.view:is_visible(nil, "finders/find-file.fn1") then
return
end

Expand Down Expand Up @@ -83,7 +83,7 @@ function M.fn(path)
end)
:iterate()

if found and explorer.view:is_visible() then
if found and explorer.view:is_visible(nil, "finders/find-file.fn2") then
explorer.renderer:draw()
explorer.view:set_cursor({ line, 0 })
end
Expand Down
6 changes: 3 additions & 3 deletions lua/nvim-tree/actions/fs/remove-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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.opts.view.float.enable and #vim.api.nvim_list_wins() < 3 then
return
end

Expand All @@ -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.opts.view.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.opts.view.float.quit_on_focus_loss then
vim.api.nvim_set_current_win(tree_winnr)
end
if M.config.actions.remove_file.close_window then
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/actions/node/open-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, "open-file.usable_win_ids")
local tree_winid = explorer and explorer.view:get_winid(tabpage, "open-file.usable_win_ids")

return vim.tbl_filter(function(id)
local bufid = vim.api.nvim_win_get_buf(id)
Expand Down Expand Up @@ -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.opts.view.float.enable then
-- ignore "WinLeave" autocmd on preview
-- because the registered "WinLeave"
-- will kill the floating window immediately
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/tree/find-file.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function M.fn(opts)
end

local explorer = core.get_explorer()
if explorer and explorer.view:is_visible() then
if explorer and explorer.view:is_visible(nil, "tree/find-file.fn") then
-- focus
if opts.focus then
lib.set_target_win()
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/tree/open.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function M.fn(opts)

local explorer = core.get_explorer()

if explorer and explorer.view:is_visible() then
if explorer and explorer.view:is_visible(nil, "open.fn") then
-- focus
lib.set_target_win()
explorer.view:focus()
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/actions/tree/toggle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function M.fn(opts, no_focus, cwd, bang)
opts.path = nil
end

if explorer and explorer.view:is_visible() then
if explorer and explorer.view:is_visible(nil, "toggle.fn") then
-- close
explorer.view:close(nil, "toggle.fn")
else
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/explorer/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ function Explorer:reload_explorer()

local projects = git.reload_all_projects()
self:refresh_nodes(projects)
if self.view:is_visible() then
if self.view:is_visible(nil, "Explorer:reload_explorer") then
self.renderer:draw()
end
event_running = false
Expand All @@ -554,7 +554,7 @@ end
---nil on no explorer or invalid view win
---@return integer[]|nil
function Explorer:get_cursor_position()
local winnr = self.view:get_winnr(nil, "Explorer:get_cursor_position")
local winnr = self.view:get_winid(nil, "Explorer:get_cursor_position")
if not winnr or not vim.api.nvim_win_is_valid(winnr) then
return
end
Expand Down
4 changes: 2 additions & 2 deletions lua/nvim-tree/explorer/live-filter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ local overlay_bufnr = 0
local overlay_winnr = 0

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
vim.api.nvim_create_autocmd("WinLeave", {
pattern = "NvimTree_*",
Expand Down Expand Up @@ -171,7 +171,7 @@ local function calculate_overlay_win_width(self)
end

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
vim.api.nvim_clear_autocmds({
event = "WinLeave",
Expand Down
Loading
Loading