mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Make sure scrollbars have the right size initially
We refresh the view after reading just enough to fill it, so that we see the initial content as quickly as possible, but then we continue reading enough lines so that we can tell how long the scrollbar needs to be, and then we refresh again. This can result in slight flicker of the scrollbar when it is first drawn with a bigger size and then jumps to a smaller size; however, that's a good tradeoff for a solution that provides both good speed and accuracy.
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"github.com/jesseduffield/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/tasks"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/spkg/bom"
|
||||
)
|
||||
@ -15,6 +16,33 @@ func (gui *Gui) resetOrigin(v *gocui.View) error {
|
||||
return v.SetOrigin(0, 0)
|
||||
}
|
||||
|
||||
// Returns the number of lines that we should read initially from a cmd task so
|
||||
// that the scrollbar has the correct size, along with the number of lines after
|
||||
// which the view is filled and we can do a first refresh.
|
||||
func (gui *Gui) linesToReadFromCmdTask(v *gocui.View) tasks.LinesToRead {
|
||||
_, height := v.Size()
|
||||
_, oy := v.Origin()
|
||||
|
||||
linesForFirstRefresh := height + oy + 10
|
||||
|
||||
// We want to read as many lines initially as necessary to let the
|
||||
// scrollbar go to its minimum height, so that the scrollbar thumb doesn't
|
||||
// change size as you scroll down.
|
||||
minScrollbarHeight := 2
|
||||
linesToReadForAccurateScrollbar := height*(height-1)/minScrollbarHeight + oy
|
||||
|
||||
// However, cap it at some arbitrary max limit, so that we don't get
|
||||
// performance problems for huge monitors or tiny font sizes
|
||||
if linesToReadForAccurateScrollbar > 5000 {
|
||||
linesToReadForAccurateScrollbar = 5000
|
||||
}
|
||||
|
||||
return tasks.LinesToRead{
|
||||
Total: linesToReadForAccurateScrollbar,
|
||||
InitialRefreshAfter: linesForFirstRefresh,
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) cleanString(s string) string {
|
||||
output := string(bom.Clean([]byte(s)))
|
||||
return utils.NormalizeLinefeeds(output)
|
||||
|
Reference in New Issue
Block a user