Clipboard uses classic, tidy opts

This commit is contained in:
Alexander Courtis
2024-11-08 15:26:32 +11:00
parent 1faa8a1762
commit 92fa49051f
2 changed files with 28 additions and 32 deletions

View File

@@ -7,6 +7,7 @@ local notify = require("nvim-tree.notify")
local find_file = require("nvim-tree.actions.finders.find-file").fn local find_file = require("nvim-tree.actions.finders.find-file").fn
local Class = require("nvim-tree.classic")
local DirectoryNode = require("nvim-tree.node.directory") local DirectoryNode = require("nvim-tree.node.directory")
---@alias ClipboardAction "copy" | "cut" ---@alias ClipboardAction "copy" | "cut"
@@ -14,35 +15,30 @@ local DirectoryNode = require("nvim-tree.node.directory")
---@alias ClipboardActionFn fun(source: string, dest: string): boolean, string? ---@alias ClipboardActionFn fun(source: string, dest: string): boolean, string?
---@class Clipboard to handle all actions.fs clipboard API ---@class (exact) Clipboard: Class
---@field config table hydrated user opts.filters
---@field private explorer Explorer ---@field private explorer Explorer
---@field private data ClipboardData ---@field private data ClipboardData
---@field private clipboard_name string ---@field private clipboard_name string
---@field private reg string ---@field private reg string
local Clipboard = {} local Clipboard = Class:extend()
---@param opts table user options ---@class Clipboard
---@param explorer Explorer ---@overload fun(args: ClipboardArgs): Clipboard
---@return Clipboard
function Clipboard:new(opts, explorer) ---@class (exact) ClipboardArgs
---@type Clipboard ---@field explorer Explorer
local o = {
explorer = explorer, ---@param args ClipboardArgs
data = { function Clipboard:new(args)
copy = {}, self.explorer = args.explorer
cut = {},
}, self.data = {
clipboard_name = opts.actions.use_system_clipboard and "system" or "neovim", copy = {},
reg = opts.actions.use_system_clipboard and "+" or "1", cut = {},
config = {
filesystem_watchers = opts.filesystem_watchers,
},
} }
setmetatable(o, self) self.clipboard_name = self.explorer.opts.actions.use_system_clipboard and "system" or "neovim"
self.__index = self self.reg = self.explorer.opts.actions.use_system_clipboard and "+" or "1"
return o
end end
---@param source string ---@param source string
@@ -252,7 +248,7 @@ function Clipboard:do_paste(node, action, action_fn)
end end
self.data[action] = {} self.data[action] = {}
if not self.config.filesystem_watchers.enable then if not self.explorer.opts.filesystem_watchers.enable then
self.explorer:reload_explorer() self.explorer:reload_explorer()
end end
end end

View File

@@ -52,17 +52,17 @@ function Explorer:new(args)
}) })
self.uid_explorer = vim.loop.hrtime() self.uid_explorer = vim.loop.hrtime()
self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {}) self.augroup_id = vim.api.nvim_create_augroup("NvimTree_Explorer_" .. self.uid_explorer, {})
self.open = true self.open = true
self.opts = config self.opts = config
self.sorters = Sorter({ explorer = self }) self.sorters = Sorter({ explorer = self })
self.renderer = Renderer({ explorer = self }) self.renderer = Renderer({ explorer = self })
self.filters = Filters({ explorer = self }) self.filters = Filters({ explorer = self })
self.live_filter = LiveFilter({ explorer = self }) self.live_filter = LiveFilter({ explorer = self })
self.marks = Marks({ explorer = self }) self.marks = Marks({ explorer = self })
self.clipboard = Clipboard:new(config, self) self.clipboard = Clipboard({ explorer = self })
self:create_autocmds() self:create_autocmds()