-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: files renamed in yazi are kept in sync in nvim
BREAKING CHANGE: this plugin now requires yazi 0.2.4 or newer.
- Loading branch information
1 parent
8697649
commit bd57653
Showing
9 changed files
with
271 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
---@class YaziConfig | ||
---@field public open_for_directories boolean | ||
|
||
---@class YaziRenameEvent | ||
---@field public type "rename" | ||
---@field public timestamp string | ||
---@field public id string | ||
---@field public data YaziEventDataRename | ||
|
||
---@class YaziEventDataRename | ||
---@field public from string | ||
---@field public to string | ||
|
||
---@class YaziBufferRenameInstruction | ||
---@field buffer integer the existing buffer number that needs renaming | ||
---@field to string the new file name that the buffer should point to |
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,25 @@ | ||
local assert = require('luassert') | ||
local utils = require('yazi.utils') | ||
|
||
describe('parsing yazi event file events', function() | ||
it('can parse rename events', function() | ||
local data = { | ||
'rename,1712242143209837,1712242143209837,{"tab":0,"from":"/Users/mikavilpas/git/yazi/file","to":"/Users/mikavilpas/git/yazi/file2"}', | ||
} | ||
|
||
local events = utils.parse_events(data) | ||
|
||
assert.are.same(events, { | ||
{ | ||
type = 'rename', | ||
timestamp = '1712242143209837', | ||
id = '1712242143209837', | ||
data = { | ||
tab = 0, | ||
from = '/Users/mikavilpas/git/yazi/file', | ||
to = '/Users/mikavilpas/git/yazi/file2', | ||
}, | ||
}, | ||
}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
local assert = require('luassert') | ||
local utils = require('yazi.utils') | ||
|
||
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 renames to files whose names match exactly', function() | ||
---@type YaziRenameEvent[] | ||
local rename_events = { | ||
{ | ||
type = 'rename', | ||
timestamp = '1712242143209837', | ||
id = '1712242143209837', | ||
data = { | ||
from = '/my-tmp/file1', | ||
to = '/my-tmp/file2', | ||
}, | ||
}, | ||
{ | ||
type = 'rename', | ||
timestamp = '1712242143209837', | ||
id = '1712242143209837', | ||
data = { | ||
from = '/my-tmp/file3', | ||
to = '/my-tmp/file4', | ||
}, | ||
}, | ||
} | ||
|
||
-- simulate the buffers being opened | ||
vim.fn.bufadd('/my-tmp/file1') | ||
vim.fn.bufadd('/my-tmp/file3') | ||
|
||
local renames = | ||
utils.get_buffers_that_need_renaming_after_yazi_exited(rename_events) | ||
|
||
assert.is_equal(#renames, 2) | ||
|
||
local result1 = renames[1] | ||
assert.is_equal('/my-tmp/file2', result1.to) | ||
assert.is_number(result1.buffer) | ||
|
||
local result2 = renames[2] | ||
assert.is_equal('/my-tmp/file4', result2.to) | ||
assert.is_number(result2.buffer) | ||
end) | ||
|
||
it( | ||
'can detect renames to buffers open in a directory that was renamed', | ||
function() | ||
---@type YaziRenameEvent[] | ||
local rename_events = { | ||
{ | ||
type = 'rename', | ||
timestamp = '1712242143209837', | ||
id = '1712242143209837', | ||
data = { | ||
from = '/my-tmp/dir1', | ||
to = '/my-tmp/dir2', | ||
}, | ||
}, | ||
} | ||
|
||
-- simulate the buffer being opened | ||
vim.fn.bufadd('/my-tmp/dir1/file') | ||
|
||
local renames = | ||
utils.get_buffers_that_need_renaming_after_yazi_exited(rename_events) | ||
|
||
assert.is_equal(#renames, 1) | ||
|
||
local result1 = renames[1] | ||
assert.is_equal('/my-tmp/dir2/file', result1.to) | ||
end | ||
) | ||
|
||
it("doesn't rename a buffer that was not renamed in yazi", function() | ||
---@type YaziRenameEvent[] | ||
local rename_events = { | ||
{ | ||
type = 'rename', | ||
timestamp = '1712242143209837', | ||
id = '1712242143209837', | ||
data = { | ||
from = '/my-tmp/not-opened-file', | ||
to = '/my-tmp/not-opened-file-renamed', | ||
}, | ||
}, | ||
} | ||
|
||
-- simulate the buffer being opened | ||
vim.fn.bufadd('/my-tmp/dir1/file') | ||
|
||
local renames = | ||
utils.get_buffers_that_need_renaming_after_yazi_exited(rename_events) | ||
|
||
assert.is_equal(#renames, 0) | ||
end) | ||
end) |