Skip to content

Commit 1840a72

Browse files
committed
refactor
1 parent 58ce17a commit 1840a72

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

lua/dired/fileops.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-- Enhanced File operations using vim.uv async functions
22
local M = {}
3+
local uv = vim.uv
34
-- Create file with content
45
M.createFile = function(path, content)
56
return {

lua/dired/init.lua

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,11 @@ UI.Window = {
377377
source_path = state.current_path,
378378
}
379379

380-
Notify.info('cut one file')
380+
if api.nvim_get_current_line():match(SEPARATOR .. '$') then
381+
Notify.info('delete folder')
382+
else
383+
Notify.info('cut one file')
384+
end
381385
end
382386

383387
state.operation_mode = nil
@@ -1134,18 +1138,73 @@ Browser.applyChanges = function(state)
11341138
end
11351139
end
11361140

1137-
for _, name in ipairs(to_delete) do
1138-
local clean_name = name:gsub(SEPARATOR .. '$', '')
1139-
local fullpath = vim.fs.joinpath(path, clean_name)
1140-
local entry = original_names[name]
1141+
-- Add recursive directory scanning for deletion
1142+
local function add_delete_operations_recursive(fullpath, name, entry, operations)
1143+
-- If it's a directory, recursively scan and add delete operations for contents
1144+
if entry.stat.type == 'directory' then
1145+
local handle = uv.fs_scandir(fullpath)
1146+
if handle then
1147+
local subdirs = {}
1148+
local files = {}
1149+
1150+
-- Collect all subdirectories and files
1151+
while true do
1152+
local entry_name = uv.fs_scandir_next(handle)
1153+
if not entry_name then
1154+
break
1155+
end
1156+
1157+
local entry_path = vim.fs.joinpath(fullpath, entry_name)
1158+
local entry_stat = uv.fs_stat(entry_path)
1159+
1160+
if entry_stat then
1161+
if entry_stat.type == 'directory' then
1162+
table.insert(subdirs, { name = entry_name, path = entry_path, stat = entry_stat })
1163+
else
1164+
table.insert(files, { name = entry_name, path = entry_path })
1165+
end
1166+
end
1167+
end
1168+
1169+
-- Process subdirectories recursively (depth-first)
1170+
for _, subdir in ipairs(subdirs) do
1171+
add_delete_operations_recursive(
1172+
subdir.path,
1173+
subdir.name,
1174+
{ stat = subdir.stat },
1175+
operations
1176+
)
1177+
end
1178+
1179+
-- Process files
1180+
for _, file in ipairs(files) do
1181+
table.insert(operations, {
1182+
type = 'delete',
1183+
path = file.path,
1184+
is_directory = false,
1185+
name = file.name,
1186+
})
1187+
end
1188+
end
1189+
end
1190+
1191+
-- Finally, add an operation to delete this item
11411192
table.insert(operations, {
11421193
type = 'delete',
11431194
path = fullpath,
11441195
is_directory = entry.stat.type == 'directory',
1145-
name = clean_name,
1196+
name = name,
11461197
})
11471198
end
11481199

1200+
for _, name in ipairs(to_delete) do
1201+
local clean_name = name:gsub(SEPARATOR .. '$', '')
1202+
local fullpath = vim.fs.joinpath(path, clean_name)
1203+
local entry = original_names[name]
1204+
1205+
add_delete_operations_recursive(fullpath, clean_name, entry, operations)
1206+
end
1207+
11491208
table.sort(to_create, function(a, b)
11501209
local a_depth = select(2, a:gsub(SEPARATOR, '')) or 0
11511210
local b_depth = select(2, b:gsub(SEPARATOR, '')) or 0

0 commit comments

Comments
 (0)