mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
docs(rename): add nvim-tree example (#27)
## Description Adds an example to `rename.md` for nvim-tree. I spent way too long obsessing over the way the code looked to make it feel like the other examples. ## Related Issue(s) N/A ## Screenshots  Co-authored-by: roy.crippen4 <roy.crippen4@archarithms.com>
This commit is contained in:
parent
5e29c1414c
commit
fb35aea5a5
1 changed files with 18 additions and 0 deletions
|
@ -35,6 +35,24 @@ vim.api.nvim_create_autocmd("User", {
|
|||
}
|
||||
```
|
||||
|
||||
## [nvim-tree](https://github.com/nvim-tree/nvim-tree.lua)
|
||||
|
||||
```lua
|
||||
local prev = { new_name = "", old_name = "" } -- Prevents duplicate events
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "NvimTreeSetup",
|
||||
callback = function()
|
||||
local events = require("nvim-tree.api").events
|
||||
events.subscribe(events.Event.NodeRenamed, function(data)
|
||||
if prev.new_name ~= data.new_name or prev.old_name ~= data.old_name then
|
||||
data = data
|
||||
Snacks.rename.on_rename_file(data.old_name, data.new_name)
|
||||
end
|
||||
end)
|
||||
end,
|
||||
})
|
||||
```
|
||||
|
||||
<!-- docgen -->
|
||||
|
||||
## 📦 Module
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue