-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: when files are deleted in yazi, they are closed in nvim
- Loading branch information
1 parent
39d0316
commit 7fe7761
Showing
10 changed files
with
241 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local assert = require('luassert') | ||
local event_handling = require('yazi.event_handling') | ||
|
||
describe('process_delete_event', function() | ||
before_each(function() | ||
-- clear all buffers | ||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do | ||
vim.api.nvim_buf_delete(buf, { force = true }) | ||
end | ||
end) | ||
|
||
it('deletes a buffer that matches the delete event exactly', function() | ||
local buffer = vim.fn.bufadd('/abc/def') | ||
|
||
---@type YaziDeleteEvent | ||
local event = { | ||
type = 'delete', | ||
timestamp = '1712766606832135', | ||
id = '1712766606832135', | ||
data = { urls = { '/abc/def' } }, | ||
} | ||
|
||
event_handling.process_delete_event(event) | ||
|
||
assert.is_false(vim.api.nvim_buf_is_valid(buffer)) | ||
end) | ||
|
||
it('deletes a buffer that matches the parent directory', function() | ||
local buffer = vim.fn.bufadd('/abc/def') | ||
|
||
---@type YaziDeleteEvent | ||
local event = { | ||
type = 'delete', | ||
timestamp = '1712766606832135', | ||
id = '1712766606832135', | ||
data = { urls = { '/abc' } }, | ||
} | ||
|
||
event_handling.process_delete_event(event) | ||
|
||
assert.is_false(vim.api.nvim_buf_is_valid(buffer)) | ||
end) | ||
|
||
it("doesn't delete a buffer that doesn't match the delete event", function() | ||
local buffer = vim.fn.bufadd('/abc/def') | ||
|
||
---@type YaziDeleteEvent | ||
local event = { | ||
type = 'delete', | ||
timestamp = '1712766606832135', | ||
id = '1712766606832135', | ||
data = { urls = { '/abc/ghi' } }, | ||
} | ||
|
||
event_handling.process_delete_event(event) | ||
|
||
assert.is_true(vim.api.nvim_buf_is_valid(buffer)) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
local assert = require('luassert') | ||
local event_handling = require('yazi.event_handling') | ||
|
||
describe('process_trash_event', function() | ||
before_each(function() | ||
-- clear all buffers | ||
for _, buf in ipairs(vim.api.nvim_list_bufs()) do | ||
vim.api.nvim_buf_delete(buf, { force = true }) | ||
end | ||
end) | ||
|
||
it('deletes a buffer that matches the trash event exactly', function() | ||
local buffer = vim.fn.bufadd('/abc/def') | ||
|
||
---@type YaziTrashEvent | ||
local event = { | ||
type = 'trash', | ||
timestamp = '1712766606832135', | ||
id = '1712766606832135', | ||
data = { urls = { '/abc/def' } }, | ||
} | ||
|
||
event_handling.process_delete_event(event) | ||
|
||
assert.is_false(vim.api.nvim_buf_is_valid(buffer)) | ||
end) | ||
|
||
it('deletes a buffer that matches the parent directory', function() | ||
local buffer = vim.fn.bufadd('/abc/def') | ||
|
||
---@type YaziTrashEvent | ||
local event = { | ||
type = 'trash', | ||
timestamp = '1712766606832135', | ||
id = '1712766606832135', | ||
data = { urls = { '/abc' } }, | ||
} | ||
|
||
event_handling.process_delete_event(event) | ||
|
||
assert.is_false(vim.api.nvim_buf_is_valid(buffer)) | ||
end) | ||
|
||
it("doesn't delete a buffer that doesn't match the trash event", function() | ||
local buffer = vim.fn.bufadd('/abc/def') | ||
|
||
---@type YaziTrashEvent | ||
local event = { | ||
type = 'trash', | ||
timestamp = '1712766606832135', | ||
id = '1712766606832135', | ||
data = { urls = { '/abc/ghi' } }, | ||
} | ||
|
||
event_handling.process_delete_event(event) | ||
|
||
assert.is_true(vim.api.nvim_buf_is_valid(buffer)) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters