@@ -20,9 +20,6 @@ M.scroll = function(command, options)
20
20
21
21
options = vim .tbl_deep_extend (" keep" , options or {}, config .get ().options )
22
22
23
- local saved_lazyredraw = vim .o .lazyredraw
24
- vim .o .lazyredraw = true
25
-
26
23
local original_view = vim .fn .winsaveview ()
27
24
local original_position = H .get_position ()
28
25
local original_buffer = vim .api .nvim_get_current_buf ()
@@ -56,6 +53,7 @@ M.scroll = function(command, options)
56
53
and original_window == final_window
57
54
and vim .fn .foldclosed (final_position .line ) == - 1 -- Not within a closed fold
58
55
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 ))
59
57
and (not options .max_delta .line or (line_delta <= options .max_delta .line ))
60
58
and (not options .max_delta .column or (column_delta <= options .max_delta .column ))
61
59
and step_delay > 0
@@ -64,11 +62,6 @@ M.scroll = function(command, options)
64
62
65
63
if is_scrollable then
66
64
vim .fn .winrestview (original_view )
67
- end
68
-
69
- vim .o .lazyredraw = saved_lazyredraw
70
-
71
- if is_scrollable then
72
65
H .scroller :start (final_position , final_view , final_buffer , final_window , step_delay , step_size , options )
73
66
else
74
67
H .cleanup (options )
@@ -424,18 +417,25 @@ H.get_position = function()
424
417
}
425
418
end
426
419
427
- --- @param p1 Position
428
- --- @param p2 Position
420
+ --- @param pos1 Position
421
+ --- @param pos2 Position
429
422
--- @param horizontal_threshold number
430
423
--- @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 )
432
425
-- 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
437
430
-- stylua: ignore end
438
431
return true
439
432
end
440
433
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
+
441
441
return M
0 commit comments