mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-12-25 12:14:19 +01:00
## Description `mini.animate`'s toggle mapping didn't take effect, presumably because `keymaps.lua` is the last one to execute on `VeryLazy`. Schedule it to correctly overwrite the default from `keymaps.lua`. I would also be interested if you don't mind to explain to me how can I find out the order of the events execution if there are multiple executions on the same event (i.e on `VeryLazy` what is the order of the execution? Is it arbitrary?) <!-- Describe the big picture of your changes to communicate to the maintainers why we should accept this pull request. --> ## Related Issue(s) None. Saw a discussion on `snacks.nvim` and OP wanted to change the mapping and when I tested with `mini.animate` Extra I noticed that its mapping wasn't overriding the default one from `keymaps.lua`. <!-- If this PR fixes any issues, please link to the issue here. - Fixes #<issue_number> --> ## Screenshots <!-- Add screenshots of the changes if applicable. --> ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines.
70 lines
2.0 KiB
Lua
70 lines
2.0 KiB
Lua
-- animations
|
|
return {
|
|
-- disable snacks scroll when animate is enabled
|
|
{
|
|
"snacks.nvim",
|
|
opts = {
|
|
scroll = { enabled = false },
|
|
},
|
|
},
|
|
|
|
-- Animates many common Neovim actions, like scrolling,
|
|
-- moving the cursor, and resizing windows.
|
|
{
|
|
"nvim-mini/mini.animate",
|
|
event = "VeryLazy",
|
|
cond = vim.g.neovide == nil,
|
|
opts = function(_, opts)
|
|
-- don't use animate when scrolling with the mouse
|
|
local mouse_scrolled = false
|
|
for _, scroll in ipairs({ "Up", "Down" }) do
|
|
local key = "<ScrollWheel" .. scroll .. ">"
|
|
vim.keymap.set({ "", "i" }, key, function()
|
|
mouse_scrolled = true
|
|
return key
|
|
end, { expr = true })
|
|
end
|
|
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
pattern = "grug-far",
|
|
callback = function()
|
|
vim.b.minianimate_disable = true
|
|
end,
|
|
})
|
|
|
|
-- schedule setting the mapping to override the default mapping from `keymaps.lua`
|
|
-- seems `keymaps.lua` is the last event to execute on `VeryLazy` and it overwrites it
|
|
vim.schedule(function()
|
|
Snacks.toggle({
|
|
name = "Mini Animate",
|
|
get = function()
|
|
return not vim.g.minianimate_disable
|
|
end,
|
|
set = function(state)
|
|
vim.g.minianimate_disable = not state
|
|
end,
|
|
}):map("<leader>ua")
|
|
end)
|
|
|
|
local animate = require("mini.animate")
|
|
return vim.tbl_deep_extend("force", opts, {
|
|
resize = {
|
|
timing = animate.gen_timing.linear({ duration = 50, unit = "total" }),
|
|
},
|
|
scroll = {
|
|
timing = animate.gen_timing.linear({ duration = 150, unit = "total" }),
|
|
subscroll = animate.gen_subscroll.equal({
|
|
predicate = function(total_scroll)
|
|
if mouse_scrolled then
|
|
mouse_scrolled = false
|
|
return false
|
|
end
|
|
return total_scroll > 1
|
|
end,
|
|
}),
|
|
},
|
|
})
|
|
end,
|
|
},
|
|
}
|