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: use a weak callback for mapping hacks #64

Merged
merged 1 commit into from
Jul 14, 2024
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
1 change: 1 addition & 0 deletions lua/cinnamon/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local defaults = {
---@class ScrollOptions
options = {
callback = nil, ---@type function?
_weak_callback = nil, ---@type function?
delay = 5, ---@type number
step_size = {
vertical = 1, ---@type number
Expand Down
12 changes: 6 additions & 6 deletions lua/cinnamon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ M.setup = function(user_config)
end)
end
end
vim.keymap.set("n", "n", function() M.scroll("n", { callback = next_search_cb }) end)
vim.keymap.set("n", "N", function() M.scroll("N", { callback = prev_search_cb }) end)
vim.keymap.set("n", "*", function() M.scroll("*", { callback = next_search_cb }) end)
vim.keymap.set("n", "#", function() M.scroll("#", { callback = prev_search_cb }) end)
vim.keymap.set("n", "g*", function() M.scroll("g*", { callback = next_search_cb }) end)
vim.keymap.set("n", "g#", function() M.scroll("g#", { callback = prev_search_cb }) end)
vim.keymap.set("n", "n", function() M.scroll("n", { _weak_callback = next_search_cb }) end)
vim.keymap.set("n", "N", function() M.scroll("N", { _weak_callback = prev_search_cb }) end)
vim.keymap.set("n", "*", function() M.scroll("*", { _weak_callback = next_search_cb }) end)
vim.keymap.set("n", "#", function() M.scroll("#", { _weak_callback = prev_search_cb }) end)
vim.keymap.set("n", "g*", function() M.scroll("g*", { _weak_callback = next_search_cb }) end)
vim.keymap.set("n", "g#", function() M.scroll("g#", { _weak_callback = prev_search_cb }) end)

-- Previous/next cursor location:
vim.keymap.set("n", "<C-o>", function() M.scroll("<C-o>") end)
Expand Down
5 changes: 3 additions & 2 deletions lua/cinnamon/scroll.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,9 @@ H.scroller = {
end,

cleanup = function(self)
if self.options.callback ~= nil then
local success, message = pcall(self.options.callback)
local callback = self.options.callback or self.options._weak_callback
if callback ~= nil then
local success, message = pcall(callback)
if not success then
utils.notify("Error executing callback: " .. message, "warn")
end
Expand Down
Loading