Skip to content

Commit 92fa490

Browse files
committed
Clipboard uses classic, tidy opts
1 parent 1faa8a1 commit 92fa490

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

lua/nvim-tree/actions/fs/clipboard.lua

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,38 @@ local notify = require("nvim-tree.notify")
77

88
local find_file = require("nvim-tree.actions.finders.find-file").fn
99

10+
local Class = require("nvim-tree.classic")
1011
local DirectoryNode = require("nvim-tree.node.directory")
1112

1213
---@alias ClipboardAction "copy" | "cut"
1314
---@alias ClipboardData table<ClipboardAction, Node[]>
1415

1516
---@alias ClipboardActionFn fun(source: string, dest: string): boolean, string?
1617

17-
---@class Clipboard to handle all actions.fs clipboard API
18-
---@field config table hydrated user opts.filters
18+
---@class (exact) Clipboard: Class
1919
---@field private explorer Explorer
2020
---@field private data ClipboardData
2121
---@field private clipboard_name string
2222
---@field private reg string
23-
local Clipboard = {}
24-
25-
---@param opts table user options
26-
---@param explorer Explorer
27-
---@return Clipboard
28-
function Clipboard:new(opts, explorer)
29-
---@type Clipboard
30-
local o = {
31-
explorer = explorer,
32-
data = {
33-
copy = {},
34-
cut = {},
35-
},
36-
clipboard_name = opts.actions.use_system_clipboard and "system" or "neovim",
37-
reg = opts.actions.use_system_clipboard and "+" or "1",
38-
config = {
39-
filesystem_watchers = opts.filesystem_watchers,
40-
},
23+
local Clipboard = Class:extend()
24+
25+
---@class Clipboard
26+
---@overload fun(args: ClipboardArgs): Clipboard
27+
28+
---@class (exact) ClipboardArgs
29+
---@field explorer Explorer
30+
31+
---@param args ClipboardArgs
32+
function Clipboard:new(args)
33+
self.explorer = args.explorer
34+
35+
self.data = {
36+
copy = {},
37+
cut = {},
4138
}
4239

43-
setmetatable(o, self)
44-
self.__index = self
45-
return o
40+
self.clipboard_name = self.explorer.opts.actions.use_system_clipboard and "system" or "neovim"
41+
self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
4642
end
4743

4844
---@param source string
@@ -252,7 +248,7 @@ function Clipboard:do_paste(node, action, action_fn)
252248
end
253249

254250
self.data[action] = {}
255-
if not self.config.filesystem_watchers.enable then
251+
if not self.explorer.opts.filesystem_watchers.enable then
256252
self.explorer:reload_explorer()
257253
end
258254
end

lua/nvim-tree/explorer/init.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ function Explorer:new(args)
5252
})
5353

5454
self.uid_explorer = vim.loop.hrtime()
55-
self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {})
55+
self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {})
5656

57-
self.open = true
58-
self.opts = config
57+
self.open = true
58+
self.opts = config
5959

60-
self.sorters = Sorter({ explorer = self })
61-
self.renderer = Renderer({ explorer = self })
62-
self.filters = Filters({ explorer = self })
63-
self.live_filter = LiveFilter({ explorer = self })
64-
self.marks = Marks({ explorer = self })
65-
self.clipboard = Clipboard:new(config, self)
60+
self.sorters = Sorter({ explorer = self })
61+
self.renderer = Renderer({ explorer = self })
62+
self.filters = Filters({ explorer = self })
63+
self.live_filter = LiveFilter({ explorer = self })
64+
self.marks = Marks({ explorer = self })
65+
self.clipboard = Clipboard({ explorer = self })
6666

6767
self:create_autocmds()
6868

0 commit comments

Comments
 (0)