Tidy up the key case switch in viewport

This commit is contained in:
Christian Rocha 2020-07-20 11:56:35 -04:00
parent b130d96434
commit 88469a499e
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018

View File

@ -7,6 +7,10 @@ import (
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
) )
const (
spacebar = " "
)
// MODEL // MODEL
type Model struct { type Model struct {
@ -292,20 +296,14 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case tea.KeyMsg: case tea.KeyMsg:
switch msg.String() { switch msg.String() {
// Down one page // Down one page
case "pgdown": case "pgdown", spacebar, "f":
fallthrough
case " ": // spacebar
fallthrough
case "f":
lines := m.ViewDown() lines := m.ViewDown()
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = ViewDown(m, lines) cmd = ViewDown(m, lines)
} }
// Up one page // Up one page
case "pgup": case "pgup", "b":
fallthrough
case "b":
lines := m.ViewUp() lines := m.ViewUp()
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = ViewUp(m, lines) cmd = ViewUp(m, lines)
@ -326,18 +324,14 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
} }
// Down one line // Down one line
case "down": case "down", "j":
fallthrough
case "j":
lines := m.LineDown(1) lines := m.LineDown(1)
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = ViewDown(m, lines) cmd = ViewDown(m, lines)
} }
// Up one line // Up one line
case "up": case "up", "k":
fallthrough
case "k":
lines := m.LineUp(1) lines := m.LineUp(1)
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = ViewUp(m, lines) cmd = ViewUp(m, lines)