Files
lazygit/pkg/integration/components/assertion_helper.go
Stefan Haller b682fb7635 Auto-scroll when dragging to create range selection in staging view
When the pointer reaches the edge of the view during a drag (or leaves
the view entirely, which mouse capture makes possible), keep scrolling
and extending the selection: slowly on the innermost edge row, faster
on the outermost row, and very fast beyond. Scrolling starts after a
short delay so that a drag merely passing near the edge doesn't scroll.

When the view loses focus mid-drag (e.g. because a popup appeared),
cancel the autoscroll and the mouse capture.
2026-07-31 08:26:35 +02:00

49 lines
1.1 KiB
Go

package components
import (
"time"
integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types"
)
const eventuallyTimeout = 2 * time.Second
type assertionHelper struct {
gui integrationTypes.GuiDriver
}
func (self *assertionHelper) matchString(matcher *TextMatcher, context string, getValue func() string) {
self.assertWithRetries(func() (bool, string) {
value := getValue()
return matcher.context(context).test(value)
})
}
// We no longer assert with retries now that lazygit tells us when it's no longer
// busy. But I'm keeping the function in case we want to re-introduce it later.
func (self *assertionHelper) assertWithRetries(test func() (bool, string)) {
ok, message := test()
if !ok {
self.fail(message)
}
}
func (self *assertionHelper) assertEventually(test func() (bool, string)) {
deadline := time.Now().Add(eventuallyTimeout)
for {
ok, message := test()
if ok {
return
}
if time.Now().After(deadline) {
self.fail(message)
return
}
time.Sleep(10 * time.Millisecond)
}
}
func (self *assertionHelper) fail(message string) {
self.gui.Fail(message)
}