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)
|
local get_hovered_url = ya.sync(function(state)
|
||||||
if not state.hovered_url then
|
return Url(cx.active.current.hovered.url)
|
||||||
state.hovered_url = cx.active.current.hovered.url
|
|
||||||
end
|
|
||||||
return Url(state.hovered_url)
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local get_selected_files = ya.sync(function(state)
|
local get_selected_files = ya.sync(function(state)
|
||||||
|
|
@ -13,8 +10,8 @@ local get_selected_files = ya.sync(function(state)
|
||||||
return selected
|
return selected
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local get_wanted_dir_name = function()
|
local get_wanted_dir_name = function(hovered_url)
|
||||||
local url = get_selected_files()[0] or get_hovered_url()
|
local url = get_selected_files()[0] or hovered_url
|
||||||
local name = url.stem
|
local name = url.stem
|
||||||
local edited, event = ya.input {
|
local edited, event = ya.input {
|
||||||
title = "Dir name:",
|
title = "Dir name:",
|
||||||
|
|
@ -29,27 +26,27 @@ local get_wanted_dir_name = function()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local get_files_to_move = function()
|
local get_files_to_move = function(hovered_url)
|
||||||
local files_to_move = get_selected_files()
|
local files_to_move = get_selected_files()
|
||||||
if #files_to_move == 0 then
|
if #files_to_move == 0 then
|
||||||
files_to_move[1] = get_hovered_url()
|
files_to_move[1] = hovered_url
|
||||||
end
|
end
|
||||||
return files_to_move
|
return files_to_move
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
entry = function(state, job)
|
entry = function(state, job)
|
||||||
state.hovered_url = undefined
|
local hovered_url = get_hovered_url()
|
||||||
local wanted_dir_name = get_wanted_dir_name()
|
local wanted_dir_name = get_wanted_dir_name(hovered_url)
|
||||||
if not wanted_dir_name then
|
if not wanted_dir_name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local ok, err = fs.create("dir", wanted_dir_name)
|
local ok, err = fs.create("dir", wanted_dir_name)
|
||||||
if not ok then
|
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
|
return
|
||||||
end
|
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)
|
ya.dbg("files to move", files_to_move)
|
||||||
for i, file in pairs(files_to_move) do
|
for i, file in pairs(files_to_move) do
|
||||||
local dest = wanted_dir_name:join(file.name)
|
local dest = wanted_dir_name:join(file.name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue