feat: trash support for linux and mac (#165)
* wip: skeleton code for trash adapter * refactor: split trash implementation for mac and linux * fix: ensure we create the .Trash/$uid dir * feat: code complete linux trash implementation * doc: write up trash features * feat: code complete mac trash implementation * cleanup: remove previous, terrible, undocumented trash feature * fix: always disabled trash * feat: show original path of trashed files * doc: add a note about calling actions directly * fix: bugs in trash implementation * fix: schedule_wrap in mac trash * doc: fix typo and line wrapping * fix: parsing of arguments to :Oil command * doc: small documentation tweaks * doc: fix awkward wording in the toggle_trash action * fix: warning on Windows when delete_to_trash = true * feat: :Oil --trash can open specific trash directories * fix: show all trash files in device root * fix: trash mtime should be sortable * fix: shorten_path handles optional trailing slash * refactor: overhaul the UI * fix: keep trash original path vtext from stacking * refactor: replace disable_changes with an error filter * fix: shorten path names in home directory relative to root * doc: small README format changes * cleanup: remove unnecessary preserve_undo logic * test: add a functional test for the freedesktop trash adapter * test: more functional tests for trash * fix: schedule a callback to avoid main loop error * refactor: clean up mutator logic * doc: some comments and type annotations
This commit is contained in:
parent
d8f0d91b10
commit
6175bd6462
27 changed files with 1580 additions and 229 deletions
|
|
@ -25,6 +25,18 @@ M.reset_editor = function()
|
|||
test_adapter.test_clear()
|
||||
end
|
||||
|
||||
local function throwiferr(err, ...)
|
||||
if err then
|
||||
error(err)
|
||||
else
|
||||
return ...
|
||||
end
|
||||
end
|
||||
|
||||
M.await = function(fn, nargs, ...)
|
||||
return throwiferr(a.wrap(fn, nargs)(...))
|
||||
end
|
||||
|
||||
M.wait_for_autocmd = a.wrap(function(autocmd, cb)
|
||||
local opts = {
|
||||
pattern = "*",
|
||||
|
|
@ -58,4 +70,48 @@ M.feedkeys = function(actions, timestep)
|
|||
a.util.sleep(timestep)
|
||||
end
|
||||
|
||||
M.actions = {
|
||||
---Open oil and wait for it to finish rendering
|
||||
---@param args string[]
|
||||
open = function(args)
|
||||
vim.schedule(function()
|
||||
vim.cmd.Oil({ args = args })
|
||||
-- If this buffer was already open, manually dispatch the autocmd to finish the wait
|
||||
if vim.b.oil_ready then
|
||||
vim.api.nvim_exec_autocmds("User", {
|
||||
pattern = "OilEnter",
|
||||
modeline = false,
|
||||
data = { buf = vim.api.nvim_get_current_buf() },
|
||||
})
|
||||
end
|
||||
end)
|
||||
M.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
end,
|
||||
|
||||
---Save all changes and wait for operation to complete
|
||||
save = function()
|
||||
vim.schedule_wrap(require("oil").save)({ confirm = false })
|
||||
M.wait_for_autocmd({ "User", pattern = "OilMutationComplete" })
|
||||
end,
|
||||
|
||||
---@param bufnr? integer
|
||||
reload = function(bufnr)
|
||||
M.await(require("oil.view").render_buffer_async, 3, bufnr or 0)
|
||||
end,
|
||||
|
||||
---Move cursor to a file or directory in an oil buffer
|
||||
---@param filename string
|
||||
focus = function(filename)
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
|
||||
local search = " " .. filename .. "$"
|
||||
for i, line in ipairs(lines) do
|
||||
if line:match(search) then
|
||||
vim.api.nvim_win_set_cursor(0, { i, 0 })
|
||||
return
|
||||
end
|
||||
end
|
||||
error("Could not find file " .. filename)
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue