-
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 moved in yazi, they stay in sync in nvim
- Loading branch information
1 parent
77ed04d
commit 0904cdd
Showing
8 changed files
with
121 additions
and
11 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,75 @@ | ||
local assert = require('luassert') | ||
local event_handling = require('yazi.event_handling') | ||
|
||
describe('get_buffers_that_need_renaming_after_yazi_exited', 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('can detect moves to files whose names match exactly', function() | ||
---@type YaziEventDataRenameOrMove | ||
local move_event = { | ||
from = '/my-tmp/file1', | ||
to = '/my-tmp/file2', | ||
} | ||
|
||
-- simulate buffers being opened | ||
vim.fn.bufadd('/my-tmp/file1') | ||
vim.fn.bufadd('/my-tmp/file_A') | ||
|
||
local instructions = | ||
event_handling.get_buffers_that_need_renaming_after_yazi_exited( | ||
move_event | ||
) | ||
|
||
assert.is_equal(vim.tbl_count(instructions), 1) | ||
|
||
local result1 = instructions[1] | ||
assert.is_equal('/my-tmp/file2', result1.path.filename) | ||
assert.is_number(result1.bufnr) | ||
end) | ||
|
||
it( | ||
'can detect moves to buffers open in a directory that was moved', | ||
function() | ||
---@type YaziEventDataRenameOrMove | ||
local move_event = { | ||
from = '/my-tmp/dir1', | ||
to = '/my-tmp/dir2', | ||
} | ||
|
||
-- simulate the buffer being opened | ||
vim.fn.bufadd('/my-tmp/dir1/file') | ||
|
||
local instructions = | ||
event_handling.get_buffers_that_need_renaming_after_yazi_exited( | ||
move_event | ||
) | ||
|
||
assert.is_equal(vim.tbl_count(instructions), 1) | ||
local result = instructions[1] | ||
assert.is_equal('/my-tmp/dir2/file', result.path.filename) | ||
end | ||
) | ||
|
||
it("doesn't move a buffer that was not moved in yazi", function() | ||
---@type YaziEventDataRenameOrMove | ||
local move_event = { | ||
from = '/my-tmp/not-opened-file', | ||
to = '/my-tmp/not-opened-file-moved', | ||
} | ||
|
||
-- simulate the buffer being opened | ||
vim.fn.bufadd('/my-tmp/dir1/file') | ||
|
||
local instructions = | ||
event_handling.get_buffers_that_need_renaming_after_yazi_exited( | ||
move_event | ||
) | ||
|
||
assert.is_equal(vim.tbl_count(instructions), 0) | ||
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