diff --git a/go.mod b/go.mod index 249fe4d46..5ec732e59 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/integrii/flaggy v1.4.0 github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d - github.com/jesseduffield/gocui v0.3.1-0.20230807090044-83a7161c8727 + github.com/jesseduffield/gocui v0.3.1-0.20230815093813-9f3df4a6da3b github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 github.com/jesseduffield/minimal/gitignore v0.3.3-0.20211018110810-9cde264e6b1e diff --git a/go.sum b/go.sum index 643db264b..5664ea2a8 100644 --- a/go.sum +++ b/go.sum @@ -179,8 +179,8 @@ github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68 h1:EQP2Tv8T github.com/jesseduffield/generics v0.0.0-20220320043834-727e535cbe68/go.mod h1:+LLj9/WUPAP8LqCchs7P+7X0R98HiFujVFANdNaxhGk= github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d h1:bO+OmbreIv91rCe8NmscRwhFSqkDJtzWCPV4Y+SQuXE= github.com/jesseduffield/go-git/v5 v5.1.2-0.20221018185014-fdd53fef665d/go.mod h1:nGNEErzf+NRznT+N2SWqmHnDnF9aLgANB1CUNEan09o= -github.com/jesseduffield/gocui v0.3.1-0.20230807090044-83a7161c8727 h1:cLq698s96uDMm0n5379doAjIKoip3/8ioWIM8pySRLY= -github.com/jesseduffield/gocui v0.3.1-0.20230807090044-83a7161c8727/go.mod h1:trXE7RRGL2hTsv+Ntk+SHLtRobg9JE138n3Ug/X2Cf4= +github.com/jesseduffield/gocui v0.3.1-0.20230815093813-9f3df4a6da3b h1:D2Qgpvo+i7bIIBbi/UtzrpyTuUj020lJeGxMa0J1jGs= +github.com/jesseduffield/gocui v0.3.1-0.20230815093813-9f3df4a6da3b/go.mod h1:trXE7RRGL2hTsv+Ntk+SHLtRobg9JE138n3Ug/X2Cf4= github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10 h1:jmpr7KpX2+2GRiE91zTgfq49QvgiqB0nbmlwZ8UnOx0= github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10/go.mod h1:aA97kHeNA+sj2Hbki0pvLslmE4CbDyhBeSSTUUnOuVo= github.com/jesseduffield/lazycore v0.0.0-20221012050358-03d2e40243c5 h1:CDuQmfOjAtb1Gms6a1p5L2P8RhbLUq5t8aL7PiQd2uY= diff --git a/vendor/github.com/jesseduffield/gocui/view.go b/vendor/github.com/jesseduffield/gocui/view.go index 939ceaa29..5c6fed903 100644 --- a/vendor/github.com/jesseduffield/gocui/view.go +++ b/vendor/github.com/jesseduffield/gocui/view.go @@ -273,25 +273,33 @@ func (v *View) FocusPoint(cx int, cy int) { ly = 0 } - // if line is above origin, move origin and set cursor to zero - // if line is below origin + height, move origin and set cursor to max - // otherwise set cursor to value - origin - if ly > lineCount { - v.cx = cx - v.cy = cy - v.oy = 0 - } else if cy < v.oy { - v.cx = cx - v.cy = 0 - v.oy = cy - } else if cy > v.oy+ly { - v.cx = cx - v.cy = ly - v.oy = cy - ly - } else { - v.cx = cx - v.cy = cy - v.oy + v.oy = calculateNewOrigin(cy, v.oy, lineCount, ly) + v.cx = cx + v.cy = cy - v.oy +} + +func calculateNewOrigin(selectedLine int, oldOrigin int, lineCount int, viewHeight int) int { + if viewHeight > lineCount { + return 0 + } else if selectedLine < oldOrigin || selectedLine > oldOrigin+viewHeight { + // If the selected line is outside the visible area, scroll the view so + // that the selected line is in the middle. + newOrigin := selectedLine - viewHeight/2 + + // However, take care not to overflow if the total line count is less + // than the view height. + maxOrigin := lineCount - viewHeight - 1 + if newOrigin > maxOrigin { + newOrigin = maxOrigin + } + if newOrigin < 0 { + newOrigin = 0 + } + + return newOrigin } + + return oldOrigin } func (s *searcher) search(str string) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 9561f09eb..539b8a488 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -124,7 +124,7 @@ github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem github.com/jesseduffield/go-git/v5/utils/merkletrie/index github.com/jesseduffield/go-git/v5/utils/merkletrie/internal/frame github.com/jesseduffield/go-git/v5/utils/merkletrie/noder -# github.com/jesseduffield/gocui v0.3.1-0.20230807090044-83a7161c8727 +# github.com/jesseduffield/gocui v0.3.1-0.20230815093813-9f3df4a6da3b ## explicit; go 1.12 github.com/jesseduffield/gocui # github.com/jesseduffield/kill v0.0.0-20220618033138-bfbe04675d10