Skip to content

Commit 625ea98

Browse files
committed
refactor(#2826): API uses Explorer's View
1 parent 620c6e0 commit 625ea98

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lua/nvim-tree/api.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
-- TODO #2826 wrap all the view methods in explorer
2-
31
local core = require("nvim-tree.core")
4-
local view = require("nvim-tree.view")
52
local utils = require("nvim-tree.utils")
63
local actions = require("nvim-tree.actions")
74
local appearance_hi_test = require("nvim-tree.appearance.hi-test")
@@ -143,9 +140,9 @@ Api.tree.focus = Api.tree.open
143140
---@field focus boolean|nil default true
144141

145142
Api.tree.toggle = wrap(actions.tree.toggle.fn)
146-
Api.tree.close = wrap(view.close)
147-
Api.tree.close_in_this_tab = wrap(view.close_this_tab_only)
148-
Api.tree.close_in_all_tabs = wrap(view.close_all_tabs)
143+
Api.tree.close = wrap_explorer_member("view", "close")
144+
Api.tree.close_in_this_tab = wrap_explorer_member("view", "close_this_tab_only")
145+
Api.tree.close_in_all_tabs = wrap_explorer_member("view", "close_all_tabs")
149146
Api.tree.reload = wrap_explorer("reload_explorer")
150147

151148
---@class ApiTreeResizeOpts
@@ -204,12 +201,12 @@ Api.tree.is_tree_buf = wrap(utils.is_nvim_tree_buf)
204201
---@field tabpage number|nil
205202
---@field any_tabpage boolean|nil default false
206203

207-
Api.tree.is_visible = wrap(view.is_visible)
204+
Api.tree.is_visible = wrap_explorer_member("view", "is_visible")
208205

209206
---@class ApiTreeWinIdOpts
210207
---@field tabpage number|nil default nil
211208

212-
Api.tree.winid = wrap(view.winid)
209+
Api.tree.winid = wrap_explorer_member("view", "winid")
213210

214211
Api.fs.create = wrap_node_or_nil(actions.fs.create_file.fn)
215212
Api.fs.remove = wrap_node(actions.fs.remove_file.fn)
@@ -241,13 +238,17 @@ local function edit(mode, node, edit_opts)
241238
local path = file_link and file_link.link_to or node.absolute_path
242239
local cur_tabpage = vim.api.nvim_get_current_tabpage()
243240

241+
local explorer = core.get_explorer()
242+
244243
actions.node.open_file.fn(mode, path)
245244

246245
edit_opts = edit_opts or {}
247246

248247
local mode_unsupported_quit_on_open = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
249248
if not mode_unsupported_quit_on_open and edit_opts.quit_on_open then
250-
view.View:close(cur_tabpage)
249+
if explorer then
250+
explorer.view:close(cur_tabpage)
251+
end
251252
end
252253

253254
local mode_unsupported_focus = mode == "drop" or mode == "tab_drop" or mode == "edit_in_place"
@@ -257,7 +258,9 @@ local function edit(mode, node, edit_opts)
257258
if mode == "tabnew" then
258259
vim.cmd(":tabprev")
259260
end
260-
view.View:focus()
261+
if explorer then
262+
explorer.view:focus()
263+
end
261264
end
262265
end
263266

0 commit comments

Comments
 (0)