Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: publishing move events to other nvim plugins #821

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
node-version-file: .nvmrc
cache: "pnpm"
- run: pnpm install
- run: pnpm tui neovim prepare
working-directory: integration-tests

# need to work around https://github.com/cypress-io/github-action/issues/1246
- run: pnpm --filter integration-tests exec cypress install
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@eslint/js": "9.22.0",
"@tui-sandbox/library": "9.6.0",
"@tui-sandbox/library": "10.0.0",
"@types/node": "22.13.10",
"@types/tinycolor2": "1.4.6",
"concurrently": "9.1.2",
Expand Down
12 changes: 10 additions & 2 deletions lua/yazi/event_handling/nvim_event_handling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ function M.emit_renamed_or_moved_event(event)
changes = {},
}

if event.type == "move" or event.type == "rename" then
event_data.changes[event.data.from] = event.data.to
if event.type == "move" then
---@type YaziMoveEvent
local move_event = event
for _, item in ipairs(move_event.data.items) do
event_data.changes[item.from] = item.to
end
elseif event.type == "rename" then
---@type YaziRenameEvent
local rename_event = event
event_data.changes[rename_event.data.from] = rename_event.data.to
elseif event.type == "bulk" then
event_data.changes = event.changes
end
Expand Down
7 changes: 5 additions & 2 deletions lua/yazi/event_handling/yazi_event_handling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ end
local function handle_rename_move_bulk_event(event_data)
local rename_instructions =
M.get_buffers_that_need_renaming_after_yazi_exited(event_data)

for _, instruction in ipairs(rename_instructions) do
utils.rename_or_close_buffer(instruction)
end
Expand All @@ -86,8 +87,10 @@ function M.process_events_emitted_from_yazi(events)

handle_rename_move_bulk_event(event.data)
elseif event.type == "move" then
---@cast event YaziMoveEvent
for _, item in ipairs(event.data.items) do
---@type YaziMoveEvent
local move_event = event

for _, item in ipairs(move_event.data.items) do
lsp_rename.file_renamed(item.from, item.to)

handle_rename_move_bulk_event(item)
Expand Down
30 changes: 15 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions spec/yazi/ya_process_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ describe("process_events()", function()
timestamp = "2021-09-01T12:00:00Z",
id = "rename_123",
data = {
from = "/tmp/old_path",
to = "/tmp/new_path",
items = {
{
from = "/tmp/old_path",
to = "/tmp/new_path",
},
},
},
},
}
Expand All @@ -194,6 +198,7 @@ describe("process_events()", function()
})

ya:process_events(events, {})

vim.wait(2000, function()
return #event_callback.calls > 0
end)
Expand Down
Loading