quick-folder: fix bugs
This commit is contained in:
parent
8d24bc9d9d
commit
ef2cf66c1a
1 changed files with 9 additions and 12 deletions
|
|
@ -1,8 +1,5 @@
|
|||
local get_hovered_url = ya.sync(function(state)
|
||||
if not state.hovered_url then
|
||||
state.hovered_url = cx.active.current.hovered.url
|
||||
end
|
||||
return Url(state.hovered_url)
|
||||
return Url(cx.active.current.hovered.url)
|
||||
end)
|
||||
|
||||
local get_selected_files = ya.sync(function(state)
|
||||
|
|
@ -13,8 +10,8 @@ local get_selected_files = ya.sync(function(state)
|
|||
return selected
|
||||
end)
|
||||
|
||||
local get_wanted_dir_name = function()
|
||||
local url = get_selected_files()[0] or get_hovered_url()
|
||||
local get_wanted_dir_name = function(hovered_url)
|
||||
local url = get_selected_files()[0] or hovered_url
|
||||
local name = url.stem
|
||||
local edited, event = ya.input {
|
||||
title = "Dir name:",
|
||||
|
|
@ -29,27 +26,27 @@ local get_wanted_dir_name = function()
|
|||
end
|
||||
end
|
||||
|
||||
local get_files_to_move = function()
|
||||
local get_files_to_move = function(hovered_url)
|
||||
local files_to_move = get_selected_files()
|
||||
if #files_to_move == 0 then
|
||||
files_to_move[1] = get_hovered_url()
|
||||
files_to_move[1] = hovered_url
|
||||
end
|
||||
return files_to_move
|
||||
end
|
||||
|
||||
return {
|
||||
entry = function(state, job)
|
||||
state.hovered_url = undefined
|
||||
local wanted_dir_name = get_wanted_dir_name()
|
||||
local hovered_url = get_hovered_url()
|
||||
local wanted_dir_name = get_wanted_dir_name(hovered_url)
|
||||
if not wanted_dir_name then
|
||||
return
|
||||
end
|
||||
local ok, err = fs.create("dir", wanted_dir_name)
|
||||
if not ok then
|
||||
ya.notify { title = "Failed to create directory", content = err }
|
||||
ya.notify { title = "Failed to create directory", content = tostring(err), timeout = 6.5, level = "error" }
|
||||
return
|
||||
end
|
||||
local files_to_move = get_files_to_move()
|
||||
local files_to_move = get_files_to_move(hovered_url)
|
||||
ya.dbg("files to move", files_to_move)
|
||||
for i, file in pairs(files_to_move) do
|
||||
local dest = wanted_dir_name:join(file.name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue