cinnamon.nvim icon indicating copy to clipboard operation
cinnamon.nvim copied to clipboard

Skip lines when scrolling

Open JoosepAlviste opened this issue 2 years ago • 3 comments

Hey!

This is related to the other feature request I made here: https://github.com/declancm/cinnamon.nvim/issues/10

The maximum delay helped me a bit, but I would still like to have scrolling for larger files. Right now, if I scroll without setting max_length, then the result is still a pretty slow scroll:

https://user-images.githubusercontent.com/9450943/180608694-a4766a34-e922-43dd-90f9-7175b9c72199.mov

With my changes, if the total scrolling would take too long (configured with max_length), then the scrolling skips some lines until a minimum delay (currently hard-coded).

https://user-images.githubusercontent.com/9450943/180608892-5c5de037-309c-4800-9ba9-072aba4bd7aa.mov

To me, this snappy smooth scrolling looks pretty good 😄

Currently, the smallest_delay (0.5ms) is just a random value that looks okay for me. But I think that a good value for this depends on the rendering speed of the terminal. A larger smallest_delay would probably be needed for slower terminals, otherwise, the animation would still take longer than desired (since the terminal can take more time to render the screen than the delay would be).

This PR is pretty WIP though, I'm not sure what should be configurable for the user and if my additions are clear enough.

Let me know what you think of this idea!

JoosepAlviste avatar Jul 23 '22 15:07 JoosepAlviste

Hi Joosep! I'm happy to merge this in once you finish the draft :)

declancm avatar Jun 04 '23 08:06 declancm

Hey! I've been using my branch on-and-off until now, but there is one bigger problem that in a larger file, the scrolling isn't consistently scrolling the same amount. For example, if I press <C-d> and <C-u>, I might not end up at the same location that I started in. This also affects searching. So, I have to turn the plugin off in bigger files (like log files with maybe more than a thousand lines?). Maybe this is because the calculations result in some floating numbers?

Anyways, I definitely wouldn't merge this PR yet as it can make the scrolling unreliable.

I haven't really had the willpower to debug this and have kind of ignored it for too long 😅

I'll try to pull myself together to try to get it working this or next week 🤞 In the meantime, do you have any comments on the structure of my changes? Do you think that the general approach makes sense?

JoosepAlviste avatar Jun 06 '23 04:06 JoosepAlviste

Hey @declancm! I think that I finally figured out what was going wrong 😄

Basically, the <c-e> and <c-y> that center the cursor on the screen were being executed the same number of times as the scrolling itself. But since moving the cursor outside of the screen already scrolls, the centering scrolling was overshooting the scrolling by quite a lot. Here's the fixup commit for that if you're interested: https://github.com/declancm/cinnamon.nvim/commit/0681a8c9dfc8b60b914eb7feabf1b2e78aa09136

If the cursor is inside the scrolloff (this case https://github.com/declancm/cinnamon.nvim/commit/0681a8c9dfc8b60b914eb7feabf1b2e78aa09136#diff-cf72e8790a6f8ac6848f2686292f6e01c8dd18e66fc65bb07d1b6aa2af6e7958L183), then we currently only scroll once, as if the line is on the screen, then it's unlikely that multiple <c-e> need to be done.

From my side, the PR is pretty much ready, I think. Please test it out as well, as I don't know the exact edge cases that need to be tested. Also, let me know if the documentation should be improved.

JoosepAlviste avatar Jun 28 '23 19:06 JoosepAlviste