Add scroll to top and bottom

This commit is contained in:
Anders Eurenius 2017-12-13 11:16:02 +01:00 committed by Anders Eurenius
parent b9a1bbec36
commit 3058ce77f4
3 changed files with 17 additions and 0 deletions

View file

@ -105,6 +105,9 @@ func init() {
ActionFunc(doScrollLeft).Register("ScrollLeft")
ActionFunc(doScrollRight).Register("ScrollRight")
ActionFunc(doScrollTop).Register("ScrollTop", termbox.KeyHome)
ActionFunc(doScrollBottom).Register("ScrollBottom", termbox.KeyEnd)
ActionFunc(doToggleSelection).Register("ToggleSelection")
ActionFunc(doToggleSelectionAndSelectNext).Register(
"ToggleSelectionAndSelectNext",
@ -416,6 +419,14 @@ func doScrollRight(ctx context.Context, state *Peco, e termbox.Event) {
state.Hub().SendPaging(ToScrollRight)
}
func doScrollTop(ctx context.Context, state *Peco, e termbox.Event) {
state.Hub().SendPaging(ToScrollTop)
}
func doScrollBottom(ctx context.Context, state *Peco, e termbox.Event) {
state.Hub().SendPaging(ToScrollBottom)
}
func doToggleSelectionAndSelectNext(ctx context.Context, state *Peco, e termbox.Event) {
toplevel, _ := ctx.Value(isTopLevelActionCall).(bool)
state.Hub().Batch(func() {

View file

@ -29,6 +29,8 @@ const (
ToScrollLeft // ToScrollLeft scrolls screen to the left
ToScrollRight // ToScrollRight scrolls screen to the right
ToLineInPage // ToLineInPage jumps to a particular line on the page
ToScrollTop // ToScrollTop
ToScrollBottom // ToScrollBottom
)
const (

View file

@ -758,6 +758,10 @@ func verticalScroll(state *Peco, l *BasicLayout, p PagingRequest) bool {
lineno -= lpp
case ToLineInPage:
lineno = loc.PerPage()*(loc.Page()-1) + p.(JumpToLineRequest).Line()
case ToScrollTop:
lineno = 0
case ToScrollBottom:
lineno = lcur - 1
}
} else {
switch p.Type() {