1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-17 01:42:45 +02:00

Read all lines from task when jumping to bottom

This commit is contained in:
Stefan Haller
2025-03-25 15:17:56 +01:00
parent 60887eddd0
commit 2b399a3c36
3 changed files with 40 additions and 11 deletions

View File

@ -95,7 +95,15 @@ func (self *ViewSelectionController) handleGotoTop() error {
} }
func (self *ViewSelectionController) handleGotoBottom() error { func (self *ViewSelectionController) handleGotoBottom() error {
if manager := self.c.GetViewBufferManagerForView(self.context.GetView()); manager != nil {
manager.ReadToEnd(func() {
self.c.OnUIThread(func() error {
v := self.Context().GetView() v := self.Context().GetView()
self.handleLineChange(v.ViewLinesHeight()) self.handleLineChange(v.ViewLinesHeight())
return nil
})
})
}
return nil return nil
} }

View File

@ -70,6 +70,9 @@ type LinesToRead struct {
// do an initial refresh. Only set for the initial read request; -1 for // do an initial refresh. Only set for the initial read request; -1 for
// subsequent requests. // subsequent requests.
InitialRefreshAfter int InitialRefreshAfter int
// Function to call after reading the lines is done
Then func()
} }
func (m *ViewBufferManager) GetTaskKey() string { func (m *ViewBufferManager) GetTaskKey() string {
@ -105,6 +108,16 @@ func (self *ViewBufferManager) ReadLines(n int) {
} }
} }
func (self *ViewBufferManager) ReadToEnd(then func()) {
if self.readLines != nil {
go utils.Safe(func() {
self.readLines <- LinesToRead{Total: -1, InitialRefreshAfter: -1, Then: then}
})
} else if then != nil {
then()
}
}
func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), prefix string, linesToRead LinesToRead, onDoneFn func()) func(TaskOpts) error { func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), prefix string, linesToRead LinesToRead, onDoneFn func()) func(TaskOpts) error {
return func(opts TaskOpts) error { return func(opts TaskOpts) error {
var onDoneOnce sync.Once var onDoneOnce sync.Once
@ -234,11 +247,17 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
case <-opts.Stop: case <-opts.Stop:
break outer break outer
case linesToRead := <-self.readLines: case linesToRead := <-self.readLines:
for i := 0; i < linesToRead.Total; i++ { callThen := func() {
if linesToRead.Then != nil {
linesToRead.Then()
}
}
for i := 0; linesToRead.Total == -1 || i < linesToRead.Total; i++ {
var ok bool var ok bool
var line []byte var line []byte
select { select {
case <-opts.Stop: case <-opts.Stop:
callThen()
break outer break outer
case line, ok = <-lineChan: case line, ok = <-lineChan:
break break
@ -258,6 +277,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
// if we're here then there's nothing left to scan from the source // if we're here then there's nothing left to scan from the source
// so we're at the EOF and can flush the stale content // so we're at the EOF and can flush the stale content
self.onEndOfInput() self.onEndOfInput()
callThen()
break outer break outer
} }
writeToView(append(line, '\n')) writeToView(append(line, '\n'))
@ -272,6 +292,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
} }
refreshViewIfStale() refreshViewIfStale()
onFirstPageShown() onFirstPageShown()
callThen()
} }
} }

View File

@ -52,7 +52,7 @@ func TestNewCmdTaskInstantStop(t *testing.T) {
return cmd, reader return cmd, reader
} }
fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1}, onDone) fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }}) _ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
@ -115,7 +115,7 @@ func TestNewCmdTask(t *testing.T) {
return cmd, reader return cmd, reader
} }
fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1}, onDone) fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
wg.Add(1) wg.Add(1)
go func() { go func() {
@ -184,37 +184,37 @@ func TestNewCmdTaskRefresh(t *testing.T) {
{ {
"total < initialRefreshAfter", "total < initialRefreshAfter",
150, 150,
LinesToRead{100, 120}, LinesToRead{100, 120, nil},
[]int{100}, []int{100},
}, },
{ {
"total == initialRefreshAfter", "total == initialRefreshAfter",
150, 150,
LinesToRead{100, 100}, LinesToRead{100, 100, nil},
[]int{100}, []int{100},
}, },
{ {
"total > initialRefreshAfter", "total > initialRefreshAfter",
150, 150,
LinesToRead{100, 50}, LinesToRead{100, 50, nil},
[]int{50, 100}, []int{50, 100},
}, },
{ {
"initialRefreshAfter == -1", "initialRefreshAfter == -1",
150, 150,
LinesToRead{100, -1}, LinesToRead{100, -1, nil},
[]int{100}, []int{100},
}, },
{ {
"totalTaskLines < initialRefreshAfter", "totalTaskLines < initialRefreshAfter",
25, 25,
LinesToRead{100, 50}, LinesToRead{100, 50, nil},
[]int{25}, []int{25},
}, },
{ {
"totalTaskLines between total and initialRefreshAfter", "totalTaskLines between total and initialRefreshAfter",
75, 75,
LinesToRead{100, 50}, LinesToRead{100, 50, nil},
[]int{50, 75}, []int{50, 75},
}, },
} }