mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-04 22:34:39 +02:00
prevent unnecessary re-renders of view
This commit is contained in:
parent
4adca84d68
commit
0af4e5a843
@ -167,6 +167,18 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
|
||||
})
|
||||
|
||||
go utils.Safe(func() {
|
||||
isViewStale := true
|
||||
writeToView := func(content []byte) {
|
||||
_, _ = self.writer.Write(content)
|
||||
isViewStale = true
|
||||
}
|
||||
refreshViewIfStale := func() {
|
||||
if isViewStale {
|
||||
self.refreshView()
|
||||
isViewStale = false
|
||||
}
|
||||
}
|
||||
|
||||
outer:
|
||||
for {
|
||||
select {
|
||||
@ -185,7 +197,7 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
|
||||
if !loaded {
|
||||
self.beforeStart()
|
||||
if prefix != "" {
|
||||
_, _ = self.writer.Write([]byte(prefix))
|
||||
writeToView([]byte(prefix))
|
||||
}
|
||||
loaded = true
|
||||
}
|
||||
@ -197,20 +209,20 @@ func (self *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), p
|
||||
self.onEndOfInput()
|
||||
break outer
|
||||
}
|
||||
_, _ = self.writer.Write(append(scanner.Bytes(), '\n'))
|
||||
writeToView(append(scanner.Bytes(), '\n'))
|
||||
|
||||
if i+1 == linesToRead.InitialRefreshAfter {
|
||||
// We have read enough lines to fill the view, so do a first refresh
|
||||
// here to show what we have. Continue reading and refresh again at
|
||||
// the end to make sure the scrollbar has the right size.
|
||||
self.refreshView()
|
||||
refreshViewIfStale()
|
||||
}
|
||||
}
|
||||
self.refreshView()
|
||||
refreshViewIfStale()
|
||||
}
|
||||
}
|
||||
|
||||
self.refreshView()
|
||||
refreshViewIfStale()
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
// it's fine if we've killed this program ourselves
|
||||
|
@ -167,25 +167,25 @@ func TestNewCmdTaskRefresh(t *testing.T) {
|
||||
"total < initialRefreshAfter",
|
||||
150,
|
||||
LinesToRead{100, 120},
|
||||
[]int{100, 100},
|
||||
[]int{100},
|
||||
},
|
||||
{
|
||||
"total == initialRefreshAfter",
|
||||
150,
|
||||
LinesToRead{100, 100},
|
||||
[]int{100, 100, 100},
|
||||
[]int{100},
|
||||
},
|
||||
{
|
||||
"total > initialRefreshAfter",
|
||||
150,
|
||||
LinesToRead{100, 50},
|
||||
[]int{50, 100, 100},
|
||||
[]int{50, 100},
|
||||
},
|
||||
{
|
||||
"initialRefreshAfter == -1",
|
||||
150,
|
||||
LinesToRead{100, -1},
|
||||
[]int{100, 100},
|
||||
[]int{100},
|
||||
},
|
||||
{
|
||||
"totalTaskLines < initialRefreshAfter",
|
||||
|
Loading…
x
Reference in New Issue
Block a user