Skip to content

Commit 8e23f17

Browse files
committed
feat(scroll): added option for animating scroll only when count is given
1 parent ecd211e commit 8e23f17

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ return {
7373
-- `window`: animate window scrolling ONLY when the cursor moves out of view
7474
mode = "cursor",
7575

76+
-- Only animate scrolling if a count is provided
77+
count_only = false,
78+
7679
-- Delay between each movement step (in ms)
7780
delay = 5,
7881

lua/cinnamon/config.lua

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local defaults = {
2323
time = 1000, ---@type number
2424
},
2525
mode = "cursor", ---@type "cursor" | "window"
26+
count_only = false, ---@type boolean
2627
},
2728
}
2829

lua/cinnamon/init.lua

+16-16
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,32 @@ M.setup = function(user_config)
7474
vim.keymap.set({ "n", "x" }, "z-", function() M.scroll("z-") end)
7575
vim.keymap.set({ "n", "x" }, "z^", function() M.scroll("z^") end)
7676
vim.keymap.set({ "n", "x" }, "z+", function() M.scroll("z+") end)
77-
vim.keymap.set({ "n", "x" }, "<C-y>", function() M.scroll("<C-y>") end)
78-
vim.keymap.set({ "n", "x" }, "<C-e>", function() M.scroll("<C-e>") end)
77+
vim.keymap.set({ "n", "x" }, "<C-y>", function() M.scroll("<C-y>", { count_only = true }) end)
78+
vim.keymap.set({ "n", "x" }, "<C-e>", function() M.scroll("<C-e>", { count_only = true }) end)
7979

8080
-- Horizontal screen scrolling:
81-
vim.keymap.set({ "n", "x" }, "zh", function() M.scroll("zh") end)
82-
vim.keymap.set({ "n", "x" }, "zl", function() M.scroll("zl") end)
81+
vim.keymap.set({ "n", "x" }, "zh", function() M.scroll("zh", { count_only = true }) end)
82+
vim.keymap.set({ "n", "x" }, "zl", function() M.scroll("zl", { count_only = true }) end)
8383
vim.keymap.set({ "n", "x" }, "zH", function() M.scroll("zH") end)
8484
vim.keymap.set({ "n", "x" }, "zL", function() M.scroll("zL") end)
8585
vim.keymap.set({ "n", "x" }, "zs", function() M.scroll("zs") end)
8686
vim.keymap.set({ "n", "x" }, "ze", function() M.scroll("ze") end)
8787

8888
-- Up/down movements:
89-
vim.keymap.set({ "n", "x" }, "k", function() M.scroll("k") end)
90-
vim.keymap.set({ "n", "x" }, "j", function() M.scroll("j") end)
91-
vim.keymap.set({ "n", "x" }, "<Up>", function() M.scroll("<Up>") end)
92-
vim.keymap.set({ "n", "x" }, "<Down>", function() M.scroll("<Down>") end)
93-
vim.keymap.set({ "n", "x" }, "gk", function() M.scroll("gk") end)
94-
vim.keymap.set({ "n", "x" }, "gj", function() M.scroll("gj") end)
95-
vim.keymap.set({ "n", "x" }, "g<Up>", function() M.scroll("g<Up>") end)
96-
vim.keymap.set({ "n", "x" }, "g<Down>", function() M.scroll("g<Down>") end)
89+
vim.keymap.set({ "n", "x" }, "k", function() M.scroll("k", { count_only = true }) end)
90+
vim.keymap.set({ "n", "x" }, "j", function() M.scroll("j", { count_only = true }) end)
91+
vim.keymap.set({ "n", "x" }, "<Up>", function() M.scroll("<Up>", { count_only = true }) end)
92+
vim.keymap.set({ "n", "x" }, "<Down>", function() M.scroll("<Down>", { count_only = true }) end)
93+
vim.keymap.set({ "n", "x" }, "gk", function() M.scroll("gk", { count_only = true }) end)
94+
vim.keymap.set({ "n", "x" }, "gj", function() M.scroll("gj", { count_only = true }) end)
95+
vim.keymap.set({ "n", "x" }, "g<Up>", function() M.scroll("g<Up>", { count_only = true }) end)
96+
vim.keymap.set({ "n", "x" }, "g<Down>", function() M.scroll("g<Down>", { count_only = true }) end)
9797

9898
-- Left/right movements:
99-
vim.keymap.set({ "n", "x" }, "h", function() M.scroll("h") end)
100-
vim.keymap.set({ "n", "x" }, "l", function() M.scroll("l") end)
101-
vim.keymap.set({ "n", "x" }, "<Left>", function() M.scroll("<Left>") end)
102-
vim.keymap.set({ "n", "x" }, "<Right>", function() M.scroll("<Right>") end)
99+
vim.keymap.set({ "n", "x" }, "h", function() M.scroll("h", { count_only = true }) end)
100+
vim.keymap.set({ "n", "x" }, "l", function() M.scroll("l", { count_only = true }) end)
101+
vim.keymap.set({ "n", "x" }, "<Left>", function() M.scroll("<Left>", { count_only = true }) end)
102+
vim.keymap.set({ "n", "x" }, "<Right>", function() M.scroll("<Right>", { count_only = true }) end)
103103
end
104104
--stylua: ignore end
105105
end

lua/cinnamon/scroll.lua

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ H.scroller = {
9090
and not vim.b.cinnamon_disable
9191
and step_count > 1
9292
and vim.fn.reg_executing() == "" -- A macro is not being executed
93+
and (not self.options.count_only or vim.v.count ~= 0)
9394
and original_buffer_id == self.buffer_id
9495
and original_window_id == self.window_id
9596
and not disabled_filetypes[vim.bo[self.buffer_id].filetype]

0 commit comments

Comments
 (0)