Skip to content

Commit e3c41ba

Browse files
committed
revise clear clipboard cmd
1 parent ec449cd commit e3c41ba

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

lua/neo-tree/clipboard/sync/universal.lua

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ end
6464
---@param filename string
6565
---@return uv.uv_fs_event_t? started true if working
6666
function UniversalBackend:_watch_file(filename)
67-
local cached = self.handles[filename]
68-
if cached then
69-
return cached
70-
end
7167
local event_handle = uv.new_fs_event()
7268
if not event_handle then
7369
log.warn("Could not watch shared clipboard on file events")
@@ -76,7 +72,7 @@ function UniversalBackend:_watch_file(filename)
7672

7773
local start_success = event_handle:start(filename, {}, function(err)
7874
if err then
79-
log.error("File handle error:", err)
75+
log.error("File handle error:", err, ", syncing will be disabled")
8076
event_handle:close()
8177
return
8278
end
@@ -182,8 +178,11 @@ function UniversalBackend:load(state)
182178
end
183179
end
184180

185-
if not self.handles[filename] then
181+
local handle = self.handles[filename]
182+
if not handle then
186183
self:_watch_file(filename)
184+
elseif not handle:is_active() then
185+
log.debug("Handle for", filename, "is dead")
187186
end
188187

189188
local file, err = io.open(filename, "r")

lua/neo-tree/defaults.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ local config = {
423423
}
424424
},
425425
["<C-f>"] = { "scroll_preview", config = {direction = -10} },
426+
["<C-r>"] = "clear_clipboard",
427+
["<C-S-r>"] = { "clear_clipboard", config = {keep_in_cwd = true} },
426428
["<C-b>"] = { "scroll_preview", config = {direction = 10} },
427429
["l"] = "focus_preview",
428430
["S"] = "open_split",

lua/neo-tree/sources/common/commands.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,22 @@ M.paste_from_clipboard = function(state, callback)
653653
end
654654

655655
M.clear_clipboard = function(state)
656-
state.clipboard = {}
657-
log.info("Cleared clipboard")
656+
if state.config and state.config.keep_in_cwd then
657+
local cwd = assert(state.path)
658+
local entries_cleared = 0
659+
for path in pairs(state.clipboard) do
660+
if not utils.is_subpath(cwd, path) then
661+
entries_cleared = entries_cleared + 1
662+
state.clipboard[path] = nil
663+
end
664+
end
665+
log.info("Cleared out", entries_cleared, "entires from clipboard")
666+
else
667+
state.clipboard = {}
668+
log.info("Cleared clipboard")
669+
end
670+
events.fire_event(events.NEO_TREE_CLIPBOARD_CHANGED, state)
671+
renderer.redraw(state)
658672
end
659673

660674
---Copies a node to a new location, using typed input.

lua/neo-tree/sources/filesystem/commands.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ local refresh = function(state)
1414
fs._navigate_internal(state, nil, nil, nil, false)
1515
end
1616

17-
local redraw = function(state)
18-
renderer.redraw(state)
19-
end
17+
local redraw = renderer.redraw
2018

2119
M.add = function(state)
2220
cc.add(state, utils.wrap(fs.show_new_children, state))
@@ -65,7 +63,7 @@ end
6563

6664
M.clear_clipboard = function(state)
6765
cc.clear_clipboard(state)
68-
redraw()
66+
redraw(state)
6967
end
7068

7169
M.delete = function(state)

0 commit comments

Comments
 (0)