@@ -44,10 +44,6 @@ function Clipboard:new(args)
4444 self .reg = self .explorer .opts .actions .use_system_clipboard and " +" or " 1"
4545end
4646
47- --- @class PasteOptions
48- --- @field use_register ? boolean
49- --- @field cut ? boolean
50-
5147--- @param source string
5248--- @param destination string
5349--- @return boolean
@@ -201,6 +197,7 @@ function Clipboard:copy(node_or_nodes)
201197 else
202198 self :bulk_clipboard (utils .filter_descendant_nodes (node_or_nodes ), self .data .cut , self .data .copy , " added to" )
203199 end
200+ self :copy_node_attribute (node_or_nodes , " absolute_path" , { notify = false })
204201end
205202
206203--- Cut one or more nodes
@@ -213,6 +210,7 @@ function Clipboard:cut(node_or_nodes)
213210 else
214211 self :bulk_clipboard (utils .filter_descendant_nodes (node_or_nodes ), self .data .copy , self .data .cut , " cut to" )
215212 end
213+ self :copy_node_attribute (node_or_nodes , " absolute_path" , { notify = false })
216214end
217215
218216--- Clear clipboard for action and reload to reflect filesystem changes from paste.
@@ -325,7 +323,7 @@ function Clipboard:get_nodes_from_reg()
325323 local content = vim .fn .getreg (self .reg )
326324
327325 if # content == 0 then
328- return
326+ return {}
329327 end
330328
331329 local nodes = {}
348346--- @param node Node
349347--- @param action ClipboardAction
350348--- @param action_fn ClipboardActionFn
351- --- @param opts ? PasteOptions
352- function Clipboard :do_paste (node , action , action_fn , opts )
349+ function Clipboard :do_paste (node , action , action_fn )
353350 if node .name == " .." then
354351 node = self .explorer
355352 else
@@ -358,7 +355,8 @@ function Clipboard:do_paste(node, action, action_fn, opts)
358355 node = dir :last_group_node ()
359356 end
360357 end
361- local clip = opts and opts .use_register and self :get_nodes_from_reg () or self .data [action ]
358+ local clip = # self .data [action ] > 0 and self .data [action ] or self :get_nodes_from_reg ()
359+
362360 if # clip == 0 then
363361 return
364362 end
@@ -426,12 +424,13 @@ end
426424
427425--- Paste cut (if present) or copy (if present)
428426--- @param node Node
429- --- @param opts ? PasteOptions
427+ --- @param opts ? { cut ?: boolean }
430428function Clipboard :paste (node , opts )
431- if self .data .cut [1 ] ~= nil or opts and opts .use_register and opts .cut then
432- self :do_paste (node , " cut" , do_cut , opts )
433- elseif self .data .copy [1 ] ~= nil or opts and opts .use_register then
434- self :do_paste (node , " copy" , do_copy , opts )
429+ opts = opts and opts or {}
430+ if self .data .cut [1 ] ~= nil or opts .cut == true then
431+ self :do_paste (node , " cut" , do_cut )
432+ else
433+ self :do_paste (node , " copy" , do_copy )
435434 end
436435end
437436
@@ -454,11 +453,15 @@ function Clipboard:print_clipboard()
454453end
455454
456455--- @param content string
457- --- @param msg ? string
458- function Clipboard :copy_to_reg (content , msg )
456+ --- @param message ? string
457+ --- @param opts ? { notify ?: boolean }
458+ function Clipboard :copy_to_reg (content , message , opts )
459+ opts = opts and opts or {}
459460 vim .fn .setreg (self .reg , type (content ) == " table" and content or { content }, " v" )
460461
461- notify .info (msg or string.format (" Copied %s to %s clipboard!" , content , self .clipboard_name ))
462+ if opts .notify ~= false then
463+ notify .info (message or string.format (" Copied %s to %s clipboard!" , content , self .clipboard_name ))
464+ end
462465end
463466
464467--- @param node Node
475478
476479--- @param node_or_nodes Node | Node[]
477480--- @param attribute " absolute_path" | " basename" | " filename" | " relative_path"
478- function Clipboard :copy_node_attribute (node_or_nodes , attribute )
481+ --- @param opts ? { notify ?: boolean }
482+ function Clipboard :copy_node_attribute (node_or_nodes , attribute , opts )
483+ opts = opts and opts or {}
479484 local content
480485 local node_attribute_getters = {
481486 basename = function (n ) return self :get_node_basename (n ) end ,
@@ -505,7 +510,7 @@ function Clipboard:copy_node_attribute(node_or_nodes, attribute)
505510 if not is_single then
506511 message = string.format (" %s %s copied to register" , # content , attribute :gsub (" _" , " " ) .. " s" )
507512 end
508- self :copy_to_reg (content , message )
513+ self :copy_to_reg (content , message , opts )
509514 end
510515end
511516
0 commit comments