Skip to content

Commit 9d3d0d2

Browse files
committed
refactor(#2826): singleton View class, WIP
1 parent a3fe0c9 commit 9d3d0d2

File tree

15 files changed

+84
-80
lines changed

15 files changed

+84
-80
lines changed

lua/nvim-tree.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function M.change_root(path, bufnr)
7474
end
7575

7676
function M.tab_enter()
77-
if view.is_visible({ any_tabpage = true }) then
77+
if view.View:is_visible({ any_tabpage = true }) then
7878
local bufname = vim.api.nvim_buf_get_name(0)
7979

8080
local ft
@@ -99,7 +99,7 @@ function M.tab_enter()
9999
end
100100

101101
function M.open_on_directory()
102-
local should_proceed = _config.hijack_directories.auto_open or view.is_visible()
102+
local should_proceed = _config.hijack_directories.auto_open or view.View:is_visible()
103103
if not should_proceed then
104104
return
105105
end
@@ -160,7 +160,7 @@ local function setup_autocommands(opts)
160160
if opts.actions.open_file.eject then
161161
view._prevent_buffer_override()
162162
else
163-
view.abandon_current_window()
163+
view.View:abandon_current_window()
164164
end
165165
end,
166166
})
@@ -687,7 +687,7 @@ end
687687

688688
function M.purge_all_state()
689689
view.View:close_all_tabs()
690-
view.abandon_all_windows()
690+
view.View:abandon_all_windows()
691691
local explorer = core.get_explorer()
692692
if explorer then
693693
require("nvim-tree.git").purge_state()

lua/nvim-tree/actions/finders/find-file.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ local running = {}
1414
---@param path string relative or absolute
1515
function M.fn(path)
1616
local explorer = core.get_explorer()
17-
if not explorer or not view.is_visible() then
17+
if not explorer or not view.View:is_visible() then
1818
return
1919
end
2020

@@ -84,9 +84,9 @@ function M.fn(path)
8484
end)
8585
:iterate()
8686

87-
if found and view.is_visible() then
87+
if found and view.View:is_visible() then
8888
explorer.renderer:draw()
89-
view.set_cursor({ line, 0 })
89+
view.View:set_cursor({ line, 0 })
9090
end
9191

9292
running[path_real] = false

lua/nvim-tree/actions/moves/item.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ local function move(explorer, where, what, skip_gitignored)
6767
end
6868

6969
if nex then
70-
view.set_cursor({ nex, 0 })
70+
view.View:set_cursor({ nex, 0 })
7171
elseif vim.o.wrapscan and first then
72-
view.set_cursor({ first, 0 })
72+
view.View:set_cursor({ first, 0 })
7373
end
7474
end
7575

@@ -189,13 +189,13 @@ local function move_prev_recursive(explorer, what, skip_gitignored)
189189

190190
-- 4.3)
191191
if node_init.name == ".." then -- root node
192-
view.set_cursor({ 1, 0 }) -- move to root node (position 1)
192+
view.View:set_cursor({ 1, 0 }) -- move to root node (position 1)
193193
else
194194
local node_init_line = utils.find_node_line(node_init)
195195
if node_init_line < 0 then
196196
return
197197
end
198-
view.set_cursor({ node_init_line, 0 })
198+
view.View:set_cursor({ node_init_line, 0 })
199199
end
200200

201201
-- 4.4)

lua/nvim-tree/actions/moves/parent.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ function M.fn(should_close)
2525
local parent = (node:get_parent_of_group() or node).parent
2626

2727
if not parent or not parent.parent then
28-
view.set_cursor({ 1, 0 })
28+
view.View:set_cursor({ 1, 0 })
2929
return
3030
end
3131

3232
local _, line = utils.find_node(parent.explorer.nodes, function(n)
3333
return n.absolute_path == parent.absolute_path
3434
end)
3535

36-
view.set_cursor({ line + 1, 0 })
36+
view.View:set_cursor({ line + 1, 0 })
3737
if should_close then
3838
parent.open = false
3939
parent.explorer.renderer:draw()

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ local function is_already_loaded(filename)
373373
end
374374

375375
local function edit_in_current_buf(filename)
376-
require("nvim-tree.view").abandon_current_window()
376+
require("nvim-tree.view").View:abandon_current_window()
377377
if M.relative_path then
378378
filename = utils.path_relative(filename, vim.fn.getcwd())
379379
end
@@ -419,7 +419,7 @@ function M.fn(mode, filename)
419419
end
420420

421421
if M.resize_window then
422-
view.resize()
422+
view.View:resize()
423423
end
424424

425425
if mode == "preview" or mode == "preview_no_picker" then

lua/nvim-tree/actions/tree/find-file.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function M.fn(opts)
4141
return
4242
end
4343

44-
if view.is_visible() then
44+
if view.View:is_visible() then
4545
-- focus
4646
if opts.focus then
4747
lib.set_target_win()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function M.fn(opts)
2323
opts.path = nil
2424
end
2525

26-
if view.is_visible() then
26+
if view.View:is_visible() then
2727
-- focus
2828
lib.set_target_win()
2929
view.focus()

lua/nvim-tree/actions/tree/resize.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function M.fn(opts)
88
if opts == nil then
99
-- reset to config values
1010
view.View:configure_width()
11-
view.resize()
11+
view.View:resize()
1212
return
1313
end
1414

@@ -17,7 +17,7 @@ function M.fn(opts)
1717

1818
if width_cfg ~= nil then
1919
view.View:configure_width(width_cfg)
20-
view.resize()
20+
view.View:resize()
2121
return
2222
end
2323

@@ -28,7 +28,7 @@ function M.fn(opts)
2828

2929
local absolute = options.absolute
3030
if type(absolute) == "number" then
31-
view.resize(absolute)
31+
view.View:resize(absolute)
3232
return
3333
end
3434

@@ -39,7 +39,7 @@ function M.fn(opts)
3939
relative_size = "+" .. relative_size
4040
end
4141

42-
view.resize(relative_size)
42+
view.View:resize(relative_size)
4343
return
4444
end
4545
end

lua/nvim-tree/actions/tree/toggle.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function M.fn(opts, no_focus, cwd, bang)
4040
opts.path = nil
4141
end
4242

43-
if view.is_visible() then
43+
if view.View:is_visible() then
4444
-- close
4545
view.View:close()
4646
else

lua/nvim-tree/commands.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ local CMDS = {
111111
bar = true,
112112
},
113113
command = function(c)
114-
view.resize(c.args)
114+
view.View:resize(c.args)
115115
end,
116116
},
117117
{

lua/nvim-tree/explorer/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ function Explorer:reload_explorer()
486486

487487
local projects = git.reload_all_projects()
488488
self:refresh_nodes(projects)
489-
if view.is_visible() then
489+
if view.View:is_visible() then
490490
self.renderer:draw()
491491
end
492492
event_running = false

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ function LiveFilter:start_filtering()
204204
self.explorer.renderer:draw()
205205
local row = require("nvim-tree.core").get_nodes_starting_line() - 1
206206
local col = #self.prefix > 0 and #self.prefix - 1 or 1
207-
view.set_cursor({ row, col })
207+
view.View:set_cursor({ row, col })
208208
-- needs scheduling to let the cursor move before initializing the window
209209
vim.schedule(function()
210210
return create_overlay(self)

lua/nvim-tree/lib.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ function M.open(opts)
111111

112112
if should_hijack_current_buf() then
113113
view.View:close_this_tab_only()
114-
view.open_in_win()
114+
view.View:open_in_win()
115115
if explorer then
116116
explorer.renderer:draw()
117117
end
118118
elseif opts.winid then
119-
view.open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid })
119+
view.View:open_in_win({ hijack_current_buf = false, resize = false, winid = opts.winid })
120120
if explorer then
121121
explorer.renderer:draw()
122122
end
123123
elseif opts.current_window then
124-
view.open_in_win({ hijack_current_buf = false, resize = false })
124+
view.View:open_in_win({ hijack_current_buf = false, resize = false })
125125
if explorer then
126126
explorer.renderer:draw()
127127
end

lua/nvim-tree/renderer/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function Renderer:draw()
113113
vim.api.nvim_win_set_cursor(view.get_winnr() or 0, cursor)
114114
end
115115

116-
view.grow_from_content()
116+
view.View:grow_from_content()
117117

118118
log.profile_end(profile)
119119

0 commit comments

Comments
 (0)