diff options
| author | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-17 16:25:32 +0100 |
|---|---|---|
| committer | Giuseppe Gadola <giusgadola@gmail.com> | 2023-02-17 16:25:32 +0100 |
| commit | 339f353f46f3a8d0c7f8d2eb369f85d1864718a3 (patch) | |
| tree | ab709fdd2398a7fc8367edd0fbe617604f4c0a51 /lua | |
| parent | fix(toggles): fix pause after hide (diff) | |
fix(toggles): fixed pausing while hidden
before this fix pausing the pets while hidden would cause an error and/or break
them and have them move twice as fast after being unhidden
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/pets/animations.lua | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lua/pets/animations.lua b/lua/pets/animations.lua index 7b9cf17..a060720 100644 --- a/lua/pets/animations.lua +++ b/lua/pets/animations.lua @@ -59,9 +59,10 @@ function M.Animation.new(sourcedir, type, style, popup, user_opts, state) end function M.Animation:start_timer() - if self.timer == nil then - self.timer = vim.loop.new_timer() + if self.timer ~= nil then + self:stop_timer() end + self.timer = vim.loop.new_timer() self.timer:start(0, 1000 / (self.speed_multiplier * 8), function() vim.schedule(function() M.Animation.next_frame(self) @@ -104,7 +105,7 @@ function M.Animation:next_frame() self.frame_counter = self.frame_counter + 1 -- pouplate the buffer with spaces to avoid image distortion - if not vim.api.nvim_buf_is_valid(self.popup.bufnr) then + if self.popup.bufnr == nil or not vim.api.nvim_buf_is_valid(self.popup.bufnr) then return end vim.api.nvim_buf_set_lines(self.popup.bufnr, 0, -1, false, lines) @@ -206,15 +207,14 @@ function M.Animation:set_state(new_state) self.popup:mount() self:start() end - end - if new_state.paused ~= nil then + elseif new_state.paused ~= nil then if self.state.paused then self:stop_timer() else if self.current_image then self.current_image:delete(0, { free = false }) end - self:start_timer() + self:start() end end end |