Implement ScrollPageUp/ScrollPageDown

Based on comment at https://github.com/peco/peco/pull/172#issuecomment-52393224
This commit is contained in:
Daisuke Maki 2014-08-17 08:20:16 +09:00
parent 908f724c01
commit 74f4c46ce8
4 changed files with 47 additions and 38 deletions

View file

@ -181,8 +181,8 @@ Example:
```json
{
"Keymap": {
"M-v": "peco.SelectPreviousPage",
"C-v": "peco.SelectNextPage",
"M-v": "peco.ScrollPageDown",
"C-v": "peco.ScrollPageUp",
"C-x,C-c": "peco.Cancel"
}
}
@ -201,9 +201,9 @@ As of v0.2.1, you can create custom combined actions. For example, if you find y
"Action": {
"foo.SelectFour": [
"peco.ToggleRangeMode",
"peco.SelectNext",
"peco.SelectNext",
"peco.SelectNext",
"peco.SelectDown",
"peco.SelectDown",
"peco.SelectDown",
"peco.ToggleRangeMode"
]
},
@ -269,8 +269,10 @@ Some keys just... don't map correctly / too easily for various reasons. Here, we
| peco.DeleteBackwardWord | Delete one word backward |
| peco.KillEndOfLine | Delete the characters under the cursor until the end of the line |
| peco.DeleteAll | Delete all entered characters |
| peco.SelectPreviousPage | Jumps to previous page |
| peco.SelectNextPage | Jumps to next page|
| peco.SelectPreviousPage | (DEPRECATED) Alias to ScrollPageUp |
| peco.SelectNextPage | (DEPRECATED) Alias to ScrollPageDown |
| peco.ScrollPageDown | Moves the selected line cursor for an entire page, downwards |
| peco.ScrollPageUp | Moves the selected line cursor for an entire page, upwards |
| peco.SelectUp | Moves the selected line cursor to one line above |
| peco.SelectDown | Moves the selected line cursor to one line below |
| peco.SelectPrevious | (DEPRECATED) Alias to SelectUp |

View file

@ -83,10 +83,11 @@ func init() {
doSelectUp(i, ev)
}).Register("SelectNext")
ActionFunc(doSelectNextPage).Register(
"SelectNextPage",
termbox.KeyArrowRight,
)
ActionFunc(doScrollPageDown).Register("ScrollPageDown", termbox.KeyArrowRight)
ActionFunc(func(i *Input, ev termbox.Event) {
i.SendStatusMsg("SelectNextPage is deprecated. Use ScrollPageDown/ScrollPageUp")
doScrollPageDown(i, ev)
}).Register("SelectNextPage")
ActionFunc(doSelectDown).Register("SelectDown", termbox.KeyArrowDown, termbox.KeyCtrlN)
ActionFunc(func(i *Input, ev termbox.Event) {
@ -94,10 +95,11 @@ func init() {
doSelectDown(i, ev)
}).Register( "SelectPrevious")
ActionFunc(doSelectPreviousPage).Register(
"SelectPreviousPage",
termbox.KeyArrowLeft,
)
ActionFunc(doScrollPageUp).Register("ScrollPageUp", termbox.KeyArrowLeft)
ActionFunc(func(i *Input, ev termbox.Event) {
i.SendStatusMsg("SelectPreviousPage is deprecated. Uselect ScrollPageDown/ScrollPageUp")
doScrollPageUp(i, ev)
}).Register("SelectPreviousPage")
ActionFunc(doToggleSelection).Register("ToggleSelection")
ActionFunc(doToggleSelectionAndSelectNext).Register(
@ -262,13 +264,13 @@ func doSelectUp(i *Input, ev termbox.Event) {
i.DrawMatches(nil)
}
func doSelectPreviousPage(i *Input, ev termbox.Event) {
i.SendPaging(ToPrevPage)
func doScrollPageUp(i *Input, ev termbox.Event) {
i.SendPaging(ToScrollPageUp)
i.DrawMatches(nil)
}
func doSelectNextPage(i *Input, ev termbox.Event) {
i.SendPaging(ToNextPage)
func doScrollPageDown(i *Input, ev termbox.Event) {
i.SendPaging(ToScrollPageDown)
i.DrawMatches(nil)
}

View file

@ -383,28 +383,33 @@ func (l *BasicLayout) DrawScreen(targets []Match) {
}
}
func (l *BasicLayout) MovePage(p PagingRequest) {
func linesPerPage() int {
_, height := termbox.Size()
perPage := height - 2 // list area is always the display area - 2 lines for prompt and status
return height - 2 // list area is always the display area - 2 lines for prompt and status
}
switch p {
case ToLineAbove:
if l.list.sortTopDown {
func (l *BasicLayout) MovePage(p PagingRequest) {
if l.list.sortTopDown {
switch p {
case ToLineAbove:
l.currentLine--
} else {
case ToLineBelow:
l.currentLine++
case ToScrollPageDown:
l.currentLine += linesPerPage()
case ToScrollPageUp:
l.currentLine -= linesPerPage()
}
case ToLineBelow:
if l.list.sortTopDown {
} else {
switch p {
case ToLineAbove:
l.currentLine++
} else {
case ToLineBelow:
l.currentLine--
}
case ToPrevPage, ToNextPage:
if p == ToPrevPage {
l.currentLine -= perPage
} else {
l.currentLine += perPage
case ToScrollPageDown:
l.currentLine -= linesPerPage()
case ToScrollPageUp:
l.currentLine += linesPerPage()
}
}

View file

@ -14,12 +14,12 @@ type PagingRequest int
const (
// ToLineAbove moves the selection to the line above
ToLineAbove PagingRequest = iota
// ToNextPage moves the selection to the next page
ToNextPage
// ToScrollPageDown moves the selection to the next page
ToScrollPageDown
// ToLineBelow moves the selection to the line below
ToLineBelow
// ToPrevPage moves the selection to the previous page
ToPrevPage
// ToScrollPageUp moves the selection to the previous page
ToScrollPageUp
)
// Loop receives requests to update the screen