diff --git a/README.md b/README.md index 478e196..ddf5618 100644 --- a/README.md +++ b/README.md @@ -66,22 +66,24 @@ return { }, ---@class ScrollOptions options = { - -- Post-movement callback - callback = nil, ---@type function? + -- Optional post-movement callback + callback = function() end, -- Delay between each movement step (in ms) delay = 7, max_delta = { - -- Maximum distance for line movements. Set to `nil` to disable - line = nil, ---@type number? - -- Maximum distance for column movements. Set to `nil` to disable - column = nil, ---@type number? + -- Maximum distance for line movements before smooth + -- scrolling is skipped. Set to `false` to disable + line = false, + -- Maximum distance for column movements before smooth + -- scrolling is skipped. Set to `false` to disable + column = false, -- Maximum duration for a movement (in ms). Automatically adjusts the step delay - time = 1000, ---@type number + time = 1000, }, -- The scrolling mode -- `cursor`: Smoothly scrolls the cursor for any movement -- `window`: Smoothly scrolls the window ONLY when the cursor moves out of view - mode = "cursor", ---@type "cursor" | "window" + mode = "cursor", }, } ``` diff --git a/lua/cinnamon/config.lua b/lua/cinnamon/config.lua index 2e5890e..9f56eab 100644 --- a/lua/cinnamon/config.lua +++ b/lua/cinnamon/config.lua @@ -13,8 +13,8 @@ local defaults = { callback = nil, ---@type function? delay = 7, ---@type number max_delta = { - line = nil, ---@type number? - column = nil, ---@type number? + line = false, ---@type number | false + column = false, ---@type number | false time = 1000, ---@type number }, mode = "cursor", ---@type "cursor" | "window" diff --git a/lua/cinnamon/scroll.lua b/lua/cinnamon/scroll.lua index c0d26f6..d9b47a4 100644 --- a/lua/cinnamon/scroll.lua +++ b/lua/cinnamon/scroll.lua @@ -56,8 +56,8 @@ M.scroll = function(command, options) and original_window == final_window and vim.fn.foldclosed(final_position.line) == -1 -- Not within a closed fold and not H.positions_within_threshold(original_position, final_position, 1, 2) - and (options.max_delta.line == nil or (line_delta <= options.max_delta.line)) - and (options.max_delta.column == nil or (column_delta <= options.max_delta.column)) + and (not options.max_delta.line or (line_delta <= options.max_delta.line)) + and (not options.max_delta.column or (column_delta <= options.max_delta.column)) and step_delay > 0 and step_size < math.huge )