Skip to content

Commit 6ac53b8

Browse files
committed
fix: use a weak callback for mapping hacks
1 parent 4cced28 commit 6ac53b8

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

lua/cinnamon/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local defaults = {
1111
---@class ScrollOptions
1212
options = {
1313
callback = nil, ---@type function?
14+
_weak_callback = nil, ---@type function?
1415
delay = 5, ---@type number
1516
step_size = {
1617
vertical = 1, ---@type number

lua/cinnamon/init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ M.setup = function(user_config)
4242
end)
4343
end
4444
end
45-
vim.keymap.set("n", "n", function() M.scroll("n", { callback = next_search_cb }) end)
46-
vim.keymap.set("n", "N", function() M.scroll("N", { callback = prev_search_cb }) end)
47-
vim.keymap.set("n", "*", function() M.scroll("*", { callback = next_search_cb }) end)
48-
vim.keymap.set("n", "#", function() M.scroll("#", { callback = prev_search_cb }) end)
49-
vim.keymap.set("n", "g*", function() M.scroll("g*", { callback = next_search_cb }) end)
50-
vim.keymap.set("n", "g#", function() M.scroll("g#", { callback = prev_search_cb }) end)
45+
vim.keymap.set("n", "n", function() M.scroll("n", { _weak_callback = next_search_cb }) end)
46+
vim.keymap.set("n", "N", function() M.scroll("N", { _weak_callback = prev_search_cb }) end)
47+
vim.keymap.set("n", "*", function() M.scroll("*", { _weak_callback = next_search_cb }) end)
48+
vim.keymap.set("n", "#", function() M.scroll("#", { _weak_callback = prev_search_cb }) end)
49+
vim.keymap.set("n", "g*", function() M.scroll("g*", { _weak_callback = next_search_cb }) end)
50+
vim.keymap.set("n", "g#", function() M.scroll("g#", { _weak_callback = prev_search_cb }) end)
5151

5252
-- Previous/next cursor location:
5353
vim.keymap.set("n", "<C-o>", function() M.scroll("<C-o>") end)

lua/cinnamon/scroll.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,9 @@ H.scroller = {
292292
end,
293293

294294
cleanup = function(self)
295-
if self.options.callback ~= nil then
296-
local success, message = pcall(self.options.callback)
295+
local callback = self.options.callback or self.options._weak_callback
296+
if callback ~= nil then
297+
local success, message = pcall(callback)
297298
if not success then
298299
utils.notify("Error executing callback: " .. message, "warn")
299300
end

0 commit comments

Comments
 (0)