Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Duplicate) Add time_scale option #91

Closed
wants to merge 1 commit into from

Conversation

hudson-bruno
Copy link

This is a duplicate of the original PR but with the requested changes added, decided to do it myself since the original is almost 2 years old

@moln-r
Copy link

moln-r commented Aug 12, 2024

any reason why this hasn't been merged? @karb94

@karb94
Copy link
Owner

karb94 commented Aug 12, 2024

I wanted to finish a large refactor first. Now that it's done I'll take another look soon.

@YodaEmbedding
Copy link

YodaEmbedding commented Nov 25, 2024

Requesting merge.

Plugin recently featured here:
https://www.reddit.com/r/neovim/comments/1gyt2ea/karb94neoscrollnvim_sphambasmearcursornvim_make/


EDIT: Looks like the PR is outdated.

I made a little hack here:

diff --git a/lua/neoscroll/scroll.lua b/lua/neoscroll/scroll.lua
index fa1b06a..29b5b2d 100644
--- a/lua/neoscroll/scroll.lua
+++ b/lua/neoscroll/scroll.lua
@@ -144,7 +144,7 @@ function scroll:compute_time_step(lines_to_scroll)
   if time_step == 0 then
     time_step = 1
   end
-  return time_step
+  return time_step * 0.1
 end
 
 ---scroll one line in the given direction

...it's very hacky, and not quite as fast as I want it, but it improves the experience a bunch.


EDIT: Still a bit too slow for my taste. I wonder if there's a nicer way to speed things up... probably have to "drop frames" or modify the number of samples that we go through. Maybe something like:

# Let f be a function defining motion s.t.
assert f(0, _) == (0, 0)
assert f(1, _) == (1, 1)

# Very naive example:
def f(s, ds, dl):
    # Constant frame rate chosen s.t. 100 lines/second:
    dt = 0.01 * dl
    # That's a bit problematic, i.e., what if 1/dt is faster than the max frame rate?
    dt = min(dt, 1 / config.max_fps)

    # Example linear (no "easing") function:
    z = s

    # NOTE: Since scroll is limited to discrete steps, it would be better to make use of ds, dl, too.

    return z, dt

# Usage:
async def animate(line_start, line_end):
    dts = []

    for s in linspace(0, 1, config.samples_scale):
        z, dt = f(s, ds = 1 / config.samples_scale, dl = line_end - line_start)
        pos = round(line_start + (line_end - line_start) * z)
        refresh_display(pos)
        dts.append(dt)
        if s != 1:
            await asyncio.sleep(dt * config.time_scale)

    assert pos == line_end
    assert math.isclose(1, sum(dts))

P.S. One other usability issue is that repeated key strokes don't speed up the animation to match the rate of the keystrokes. So holding down Ctrl+F feels unresponsive.

@karb94
Copy link
Owner

karb94 commented Nov 27, 2024

Apologies, I added this feature a while ago but somehow forgot to push it. I just added it in 81c47f9 so we can close this. Feel free to open an issue if it doesn't work as expected.

PS: @YodaEmbedding, please let's try to keep different topics separate so open another issue if you want to suggest another feature or raise another issue. Notice what you suggest at the end has already been proposed in #70 so feel free to comment there instead.

@karb94 karb94 closed this Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants