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

Move horizontal scroll when it required by selection #12

Merged
merged 5 commits into from Oct 4, 2018

Conversation

@Kvaz1r
Copy link

commented Aug 4, 2018

For nelsam/vidar#136

If this approach good enough I also can add analogic addes for vertical scroll.


from, to := t.horizScroll.ScrollPosition()
L := to - from
delta := 10

This comment has been minimized.

Copy link
@nelsam

nelsam Aug 5, 2018

Owner

I'd like this to be a constant, e.g.

const SelectionScrollBuffer = 10`
@nelsam

This comment has been minimized.

Copy link
Owner

commented Aug 5, 2018

On my computer, this scrolls very fast. I'd like to see it edited with something like the following:

const MaxSelectionScrollRate = 100 * time.Millisecond
now := time.Now()
if now.Before(t.lastSelectionScroll.Add(MaxSelectionScrollRate)) {
    return
}
t.lastSelectionScroll = now

I also noticed that this only scrolls when you move your mouse ... is that how we want it to work? We could alternatively have the scrolling start as soon as the mouse moves in to that buffer zone, then stop as soon as it moves out, e.g.

if t.stopScrolling != nil {
    return
}
t.stopScrolling = make(chan struct{})
go func() {
    ticker := time.NewTicker(MaxSelectionScrollRate)
    defer func() {
        ticker.Stop()
        t.stopScrolling = nil
    }()
    for range ticker.C {
        select {
        case <-t.stopScrolling:
            return
        default:
            t.updateSelectionScroll()
        }
    }
}()

^ in that code, we would need to run close(t.stopScrolling) when the mouse moves away from the edge of the editor.

@Kvaz1r

This comment has been minimized.

Copy link
Author

commented Aug 5, 2018

On my computer, this scrolls very fast. I'd like to see it edited with something like the following:

Agree, but not sure that it would be enough. Maybe excess of selection - also consequence of the fact that mouse don't move. I am going to check it.

I also noticed that this only scrolls when you move your mouse ... is that how we want it to work?

I think so. I don't see many difference between these approaches for lines with long ~ 2 x width of screen and this is a main case when scrolling needed. For longer lines absence of explicit action will give selection to end (start) of line, isn't?

This also updates the scrolling to scroll faster the closer to the edge that the mouse is.
@nelsam

This comment has been minimized.

Copy link
Owner

commented Aug 5, 2018

I played with your changes for a while and came up with something based on what you were doing, but with a few changes to how the selection scrolling works. It's not completely done, but it shows an adjustable scroll rate (it scrolls faster as your mouse gets closer to the edge) and constant scrolling while your mouse stays still.

make selection scrolling happen without needing to wriggle the mouse
@Kvaz1r

This comment has been minimized.

Copy link
Author

commented Aug 5, 2018

Great, I quickly tested your solution and it works very good.

Kvaz1r added 2 commits Sep 9, 2018
@nelsam nelsam merged commit 194d8c2 into nelsam:master Oct 4, 2018
1 check passed
1 check passed
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
@Kvaz1r Kvaz1r deleted the Kvaz1r:hscroll_updates branch Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.