Compare commits
2 commits
69d85b8de1
...
2d6f6e825f
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d6f6e825f | |||
| 047338a6dd |
5 changed files with 177 additions and 108 deletions
|
|
@ -311,6 +311,12 @@ prompt_save_on_select_new_entry *canola.prompt_save_on_select_new_e
|
||||||
When this option is `true`, Canola will prompt you to save before entering a file or
|
When this option is `true`, Canola will prompt you to save before entering a file or
|
||||||
directory that is pending within canola, but does not exist on disk.
|
directory that is pending within canola, but does not exist on disk.
|
||||||
|
|
||||||
|
cleanup_buffers_on_delete *canola.cleanup_buffers_on_delete*
|
||||||
|
type: `boolean` default: `false`
|
||||||
|
When `true`, canola will wipe any open buffer whose path matches a file that
|
||||||
|
was successfully deleted via canola. This prevents stale buffers from
|
||||||
|
appearing in the jumplist after a deletion.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
API *canola-api*
|
API *canola-api*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ Bugs fixed in this fork that remain open upstream.
|
||||||
| [#642](https://github.com/stevearc/oil.nvim/issues/642) | W10 warning under `nvim -R` | [`ca834cf`](https://github.com/barrettruth/canola.nvim/commit/ca834cf) |
|
| [#642](https://github.com/stevearc/oil.nvim/issues/642) | W10 warning under `nvim -R` | [`ca834cf`](https://github.com/barrettruth/canola.nvim/commit/ca834cf) |
|
||||||
| [#670](https://github.com/stevearc/oil.nvim/issues/670) | Multi-directory cmdline args ignored | [#11](https://github.com/barrettruth/canola.nvim/pull/11) ([`70861e5`](https://github.com/barrettruth/canola.nvim/commit/70861e5)) |
|
| [#670](https://github.com/stevearc/oil.nvim/issues/670) | Multi-directory cmdline args ignored | [#11](https://github.com/barrettruth/canola.nvim/pull/11) ([`70861e5`](https://github.com/barrettruth/canola.nvim/commit/70861e5)) |
|
||||||
| [#673](https://github.com/stevearc/oil.nvim/issues/673) | Symlink newlines crash | [`9110a1a`](https://github.com/barrettruth/canola.nvim/commit/9110a1a) |
|
| [#673](https://github.com/stevearc/oil.nvim/issues/673) | Symlink newlines crash | [`9110a1a`](https://github.com/barrettruth/canola.nvim/commit/9110a1a) |
|
||||||
|
| [#612](https://github.com/stevearc/oil.nvim/issues/612) | Delete buffers on file delete | [#73](https://github.com/barrettruth/canola.nvim/pull/73) ([`047338a`](https://github.com/barrettruth/canola.nvim/commit/047338a)) |
|
||||||
| [#710](https://github.com/stevearc/oil.nvim/issues/710) | buftype empty on BufEnter | [#10](https://github.com/barrettruth/canola.nvim/pull/10) ([`01b860e`](https://github.com/barrettruth/canola.nvim/commit/01b860e)) |
|
| [#710](https://github.com/stevearc/oil.nvim/issues/710) | buftype empty on BufEnter | [#10](https://github.com/barrettruth/canola.nvim/pull/10) ([`01b860e`](https://github.com/barrettruth/canola.nvim/commit/01b860e)) |
|
||||||
|
|
||||||
## Open upstream PRs
|
## Open upstream PRs
|
||||||
|
|
@ -56,7 +57,7 @@ cherry-picked PR, `not actionable` = can't/won't fix, `tracking` = known/not yet
|
||||||
addressed, `open` = not yet triaged.
|
addressed, `open` = not yet triaged.
|
||||||
|
|
||||||
| Issue | Status | Notes |
|
| Issue | Status | Notes |
|
||||||
| ------------------------------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
| [#85](https://github.com/stevearc/oil.nvim/issues/85) | open | Git status column (P2) |
|
| [#85](https://github.com/stevearc/oil.nvim/issues/85) | open | Git status column (P2) |
|
||||||
| [#95](https://github.com/stevearc/oil.nvim/issues/95) | open | Undo after renaming files (P1) |
|
| [#95](https://github.com/stevearc/oil.nvim/issues/95) | open | Undo after renaming files (P1) |
|
||||||
| [#117](https://github.com/stevearc/oil.nvim/issues/117) | open | Move file into new dir via slash in name (P1, related to [#708](https://github.com/stevearc/oil.nvim/pull/708)) |
|
| [#117](https://github.com/stevearc/oil.nvim/issues/117) | open | Move file into new dir via slash in name (P1, related to [#708](https://github.com/stevearc/oil.nvim/pull/708)) |
|
||||||
|
|
@ -124,7 +125,7 @@ addressed, `open` = not yet triaged.
|
||||||
| [#599](https://github.com/stevearc/oil.nvim/issues/599) | open | user:group display and manipulation (P2) |
|
| [#599](https://github.com/stevearc/oil.nvim/issues/599) | open | user:group display and manipulation (P2) |
|
||||||
| [#607](https://github.com/stevearc/oil.nvim/issues/607) | open | Per-host SCP args (P2) |
|
| [#607](https://github.com/stevearc/oil.nvim/issues/607) | open | Per-host SCP args (P2) |
|
||||||
| [#609](https://github.com/stevearc/oil.nvim/issues/609) | open | Cursor placement via Snacks picker |
|
| [#609](https://github.com/stevearc/oil.nvim/issues/609) | open | Cursor placement via Snacks picker |
|
||||||
| [#612](https://github.com/stevearc/oil.nvim/issues/612) | open | Delete buffers on file delete (P2) |
|
| [#612](https://github.com/stevearc/oil.nvim/issues/612) | fixed | Delete buffers on file delete — `cleanup_buffers_on_delete` option |
|
||||||
| [#615](https://github.com/stevearc/oil.nvim/issues/615) | open | Cursor at name column on o/O (P2) |
|
| [#615](https://github.com/stevearc/oil.nvim/issues/615) | open | Cursor at name column on o/O (P2) |
|
||||||
| [#617](https://github.com/stevearc/oil.nvim/issues/617) | open | Filetype by actual filetype (P2) |
|
| [#617](https://github.com/stevearc/oil.nvim/issues/617) | open | Filetype by actual filetype (P2) |
|
||||||
| [#621](https://github.com/stevearc/oil.nvim/issues/621) | open | Toggle function for regular windows (P2) |
|
| [#621](https://github.com/stevearc/oil.nvim/issues/621) | open | Toggle function for regular windows (P2) |
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ local default_config = {
|
||||||
},
|
},
|
||||||
-- Send deleted files to the trash instead of permanently deleting them (:help canola-trash)
|
-- Send deleted files to the trash instead of permanently deleting them (:help canola-trash)
|
||||||
delete_to_trash = false,
|
delete_to_trash = false,
|
||||||
|
-- Wipe open buffers for files deleted via canola (:help canola.cleanup_buffers_on_delete)
|
||||||
|
cleanup_buffers_on_delete = false,
|
||||||
-- Skip the confirmation popup for simple operations (:help canola.skip_confirm_for_simple_edits)
|
-- Skip the confirmation popup for simple operations (:help canola.skip_confirm_for_simple_edits)
|
||||||
skip_confirm_for_simple_edits = false,
|
skip_confirm_for_simple_edits = false,
|
||||||
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
-- Selecting a new/moved/renamed file or directory will prompt you to save changes first
|
||||||
|
|
@ -232,6 +234,7 @@ default_config.view_options.highlight_filename = nil
|
||||||
---@field buf_options table<string, any>
|
---@field buf_options table<string, any>
|
||||||
---@field win_options table<string, any>
|
---@field win_options table<string, any>
|
||||||
---@field delete_to_trash boolean
|
---@field delete_to_trash boolean
|
||||||
|
---@field cleanup_buffers_on_delete boolean
|
||||||
---@field skip_confirm_for_simple_edits boolean
|
---@field skip_confirm_for_simple_edits boolean
|
||||||
---@field prompt_save_on_select_new_entry boolean
|
---@field prompt_save_on_select_new_entry boolean
|
||||||
---@field cleanup_delay_ms integer
|
---@field cleanup_delay_ms integer
|
||||||
|
|
@ -263,6 +266,7 @@ local M = {}
|
||||||
---@field buf_options? table<string, any> Buffer-local options to use for canola buffers
|
---@field buf_options? table<string, any> Buffer-local options to use for canola buffers
|
||||||
---@field win_options? table<string, any> Window-local options to use for canola buffers
|
---@field win_options? table<string, any> Window-local options to use for canola buffers
|
||||||
---@field delete_to_trash? boolean Send deleted files to the trash instead of permanently deleting them (:help canola-trash).
|
---@field delete_to_trash? boolean Send deleted files to the trash instead of permanently deleting them (:help canola-trash).
|
||||||
|
---@field cleanup_buffers_on_delete? boolean Wipe open buffers for files deleted via canola (:help canola.cleanup_buffers_on_delete).
|
||||||
---@field skip_confirm_for_simple_edits? boolean Skip the confirmation popup for simple operations (:help canola.skip_confirm_for_simple_edits).
|
---@field skip_confirm_for_simple_edits? boolean Skip the confirmation popup for simple operations (:help canola.skip_confirm_for_simple_edits).
|
||||||
---@field prompt_save_on_select_new_entry? boolean Selecting a new/moved/renamed file or directory will prompt you to save changes first (:help prompt_save_on_select_new_entry).
|
---@field prompt_save_on_select_new_entry? boolean Selecting a new/moved/renamed file or directory will prompt you to save changes first (:help prompt_save_on_select_new_entry).
|
||||||
---@field cleanup_delay_ms? integer Canola will automatically delete hidden buffers after this delay. You can set the delay to false to disable cleanup entirely. Note that the cleanup process only starts when none of the canola buffers are currently displayed.
|
---@field cleanup_delay_ms? integer Canola will automatically delete hidden buffers after this delay. You can set the delay to false to disable cleanup entirely. Note that the cleanup process only starts when none of the canola buffers are currently displayed.
|
||||||
|
|
|
||||||
|
|
@ -420,6 +420,21 @@ M.process_actions = function(actions, cb)
|
||||||
finished = true
|
finished = true
|
||||||
progress:close()
|
progress:close()
|
||||||
progress = nil
|
progress = nil
|
||||||
|
if config.cleanup_buffers_on_delete and not err then
|
||||||
|
for _, action in ipairs(actions) do
|
||||||
|
if action.type == 'delete' then
|
||||||
|
local scheme, path = util.parse_url(action.url)
|
||||||
|
if config.adapters[scheme] == 'files' then
|
||||||
|
assert(path)
|
||||||
|
local os_path = fs.posix_to_os_path(path)
|
||||||
|
local bufnr = vim.fn.bufnr(os_path)
|
||||||
|
if bufnr ~= -1 then
|
||||||
|
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
vim.api.nvim_exec_autocmds(
|
vim.api.nvim_exec_autocmds(
|
||||||
'User',
|
'User',
|
||||||
{ pattern = 'CanolaActionsPost', modeline = false, data = { err = err, actions = actions } }
|
{ pattern = 'CanolaActionsPost', modeline = false, data = { err = err, actions = actions } }
|
||||||
|
|
|
||||||
|
|
@ -163,4 +163,47 @@ describe('files adapter', function()
|
||||||
assert.equals(vim.fn.fnamemodify(tmpdir.path, ':p') .. 'file.rb', vim.api.nvim_buf_get_name(0))
|
assert.equals(vim.fn.fnamemodify(tmpdir.path, ':p') .. 'file.rb', vim.api.nvim_buf_get_name(0))
|
||||||
assert.equals(tmpdir.path .. '/file.rb', vim.fn.bufname())
|
assert.equals(tmpdir.path .. '/file.rb', vim.fn.bufname())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe('cleanup_buffers_on_delete', function()
|
||||||
|
local cache = require('canola.cache')
|
||||||
|
local config = require('canola.config')
|
||||||
|
local mutator = require('canola.mutator')
|
||||||
|
|
||||||
|
before_each(function()
|
||||||
|
config.cleanup_buffers_on_delete = true
|
||||||
|
end)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
config.cleanup_buffers_on_delete = false
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('wipes the buffer for a deleted file', function()
|
||||||
|
tmpdir:create({ 'a.txt' })
|
||||||
|
local dirurl = 'canola://' .. vim.fn.fnamemodify(tmpdir.path, ':p')
|
||||||
|
local filepath = vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
|
||||||
|
cache.create_and_store_entry(dirurl, 'a.txt', 'file')
|
||||||
|
vim.cmd.edit({ args = { filepath } })
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
local url = 'canola://' .. filepath
|
||||||
|
test_util.await(mutator.process_actions, 2, {
|
||||||
|
{ type = 'delete', url = url, entry_type = 'file' },
|
||||||
|
})
|
||||||
|
assert.is_false(vim.api.nvim_buf_is_valid(bufnr))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('does not wipe the buffer when disabled', function()
|
||||||
|
config.cleanup_buffers_on_delete = false
|
||||||
|
tmpdir:create({ 'b.txt' })
|
||||||
|
local dirurl = 'canola://' .. vim.fn.fnamemodify(tmpdir.path, ':p')
|
||||||
|
local filepath = vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b.txt'
|
||||||
|
cache.create_and_store_entry(dirurl, 'b.txt', 'file')
|
||||||
|
vim.cmd.edit({ args = { filepath } })
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
local url = 'canola://' .. filepath
|
||||||
|
test_util.await(mutator.process_actions, 2, {
|
||||||
|
{ type = 'delete', url = url, entry_type = 'file' },
|
||||||
|
})
|
||||||
|
assert.is_true(vim.api.nvim_buf_is_valid(bufnr))
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue