diff --git a/quick-folder.yazi/main.lua b/quick-folder.yazi/main.lua index b9f083d..63cf56e 100644 --- a/quick-folder.yazi/main.lua +++ b/quick-folder.yazi/main.lua @@ -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)