@@ -7,7 +7,6 @@ local M = {}
77local BASE_TIME_INTERVAL = 17
88
99local animating = false
10- local timer = nil
1110local previous_time = 0
1211local target_position = { 0 , 0 }
1312local current_corners = { { 0 , 0 }, { 0 , 0 }, { 0 , 0 }, { 0 , 0 } }
@@ -246,7 +245,7 @@ local function update_particles(time_interval)
246245 local i = 1
247246 while i <= # particles do
248247 local particle = particles [i ]
249- particle .lifetime = particle .lifetime - config . time_interval
248+ particle .lifetime = particle .lifetime - time_interval
250249
251250 if particle .lifetime <= 0 then
252251 table.remove (particles , i )
@@ -311,10 +310,6 @@ local function shrink_volume(corners)
311310end
312311
313312local function stop_animation ()
314- if timer == nil then return end
315- timer :stop ()
316- timer :close ()
317- timer = nil
318313 animating = false
319314 previous_time = 0
320315end
@@ -373,7 +368,9 @@ local function redraw_cmd_mode(force)
373368end
374369
375370local function animate ()
376- animating = true
371+ local start_time = vim .uv .now ()
372+ if not animating then return end
373+
377374 local must_redraw_cmd_mode = check_smear_outside_cmd_row ()
378375 local time_interval = get_effective_time_interval ()
379376 local index_head , index_tail = update (time_interval )
@@ -461,12 +458,15 @@ local function animate()
461458 draw .draw_particles (particles , target_position )
462459 draw .draw_quad (drawn_corners , target_position , cursor_is_vertical_bar (), gradient_origin , gradient_direction_scaled )
463460 redraw_cmd_mode (must_redraw_cmd_mode )
461+
462+ local end_time = vim .uv .now ()
463+ vim .defer_fn (animate , math.max (0 , config .time_interval - (end_time - start_time )))
464464end
465465
466466local function start_anination ()
467- if timer ~= nil then return end
468- timer = vim . uv . new_timer ()
469- timer : start ( 0 , config . time_interval , vim . schedule_wrap ( animate ) )
467+ if animating then return end
468+ animating = true
469+ animate ( )
470470end
471471
472472local function set_stiffnesses ()
0 commit comments