Skip to content

Commit 2fbef7f

Browse files
committed
fix: don't set lazyredraw during command since it breaks movements like 'n'
Fixes #50
1 parent 1771305 commit 2fbef7f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lua/cinnamon/scroll.lua

+15-15
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ M.scroll = function(command, options)
2020

2121
options = vim.tbl_deep_extend("keep", options or {}, config.get().options)
2222

23-
local saved_lazyredraw = vim.o.lazyredraw
24-
vim.o.lazyredraw = true
25-
2623
local original_view = vim.fn.winsaveview()
2724
local original_position = H.get_position()
2825
local original_buffer = vim.api.nvim_get_current_buf()
@@ -56,6 +53,7 @@ M.scroll = function(command, options)
5653
and original_window == final_window
5754
and vim.fn.foldclosed(final_position.line) == -1 -- Not within a closed fold
5855
and not H.positions_within_threshold(original_position, final_position, 1, 2)
56+
and (options.mode == "cursor" or H.window_scrolled(original_view, final_view))
5957
and (not options.max_delta.line or (line_delta <= options.max_delta.line))
6058
and (not options.max_delta.column or (column_delta <= options.max_delta.column))
6159
and step_delay > 0
@@ -64,11 +62,6 @@ M.scroll = function(command, options)
6462

6563
if is_scrollable then
6664
vim.fn.winrestview(original_view)
67-
end
68-
69-
vim.o.lazyredraw = saved_lazyredraw
70-
71-
if is_scrollable then
7265
H.scroller:start(final_position, final_view, final_buffer, final_window, step_delay, step_size, options)
7366
else
7467
H.cleanup(options)
@@ -424,18 +417,25 @@ H.get_position = function()
424417
}
425418
end
426419

427-
---@param p1 Position
428-
---@param p2 Position
420+
---@param pos1 Position
421+
---@param pos2 Position
429422
---@param horizontal_threshold number
430423
---@param vertical_threshold number
431-
H.positions_within_threshold = function(p1, p2, horizontal_threshold, vertical_threshold)
424+
H.positions_within_threshold = function(pos1, pos2, horizontal_threshold, vertical_threshold)
432425
-- stylua: ignore start
433-
if math.abs(p1.line - p2.line) > horizontal_threshold then return false end
434-
if math.abs(p1.col - p2.col) > vertical_threshold then return false end
435-
if math.abs(p1.winline - p2.winline) > horizontal_threshold then return false end
436-
if math.abs(p1.wincol - p2.wincol) > vertical_threshold then return false end
426+
if math.abs(pos1.line - pos2.line) > horizontal_threshold then return false end
427+
if math.abs(pos1.col - pos2.col) > vertical_threshold then return false end
428+
if math.abs(pos1.winline - pos2.winline) > horizontal_threshold then return false end
429+
if math.abs(pos1.wincol - pos2.wincol) > vertical_threshold then return false end
437430
-- stylua: ignore end
438431
return true
439432
end
440433

434+
---@param view1 table
435+
---@param view2 table
436+
---@return boolean
437+
H.window_scrolled = function(view1, view2)
438+
return view1.topline ~= view2.topline or view1.leftcol ~= view2.leftcol
439+
end
440+
441441
return M

0 commit comments

Comments
 (0)