Remove redundant viewport commands

This commit is contained in:
Christian Rocha 2020-07-17 18:22:51 -04:00
parent 2f909886c1
commit dbb1d93970
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018

View File

@ -218,9 +218,9 @@ func Sync(m Model) tea.Cmd {
) )
} }
// ViewDown is a high performance command that moves the viewport up by one // ViewDown is a high performance command that moves the viewport up by a given
// viewport height. Use Model.ViewDown to get the lines that should be // numer of lines. Use Model.ViewDown to get the lines that should be rendered.
// rendered. For example: // For example:
// //
// lines := model.ViewDown(1) // lines := model.ViewDown(1)
// cmd := ViewDown(m, lines) // cmd := ViewDown(m, lines)
@ -232,8 +232,8 @@ func ViewDown(m Model, lines []string) tea.Cmd {
return tea.ScrollDown(lines, m.YPosition, m.YPosition+m.Height) return tea.ScrollDown(lines, m.YPosition, m.YPosition+m.Height)
} }
// ViewUp is a high performance command the moves the viewport down by one // ViewUp is a high performance command the moves the viewport down by a given
// viewport height. Use Model.ViewDown to get the lines that should be // number of lines height. Use Model.ViewDown to get the lines that should be
// rendered. // rendered.
func ViewUp(m Model, lines []string) tea.Cmd { func ViewUp(m Model, lines []string) tea.Cmd {
if len(lines) == 0 { if len(lines) == 0 {
@ -242,46 +242,6 @@ func ViewUp(m Model, lines []string) tea.Cmd {
return tea.ScrollUp(lines, m.YPosition, m.YPosition+m.Height) return tea.ScrollUp(lines, m.YPosition, m.YPosition+m.Height)
} }
// HalfViewDown is a high performance command the moves the viewport down by
// half of the height of the viewport. Use Model.HalfViewDown to get the lines
// that should be rendered.
func HalfViewDown(m Model, lines []string) tea.Cmd {
if len(lines) == 0 {
return nil
}
return tea.ScrollDown(lines, m.YPosition, m.YPosition+m.Height)
}
// HalfViewUp is a high performance command the moves the viewport up by
// half of the height of the viewport. Use Model.HalfViewUp to get the lines
// that should be rendered.
func HalfViewUp(m Model, lines []string) tea.Cmd {
if len(lines) == 0 {
return nil
}
return tea.ScrollUp(lines, m.YPosition, m.YPosition+m.Height)
}
// LineDown is a high performance command the moves the viewport down by
// a given number of lines. Use Model.LineDown to get the lines that should be
// rendered.
func LineDown(m Model, lines []string) tea.Cmd {
if len(lines) == 0 {
return nil
}
return tea.ScrollDown(lines, m.YPosition, m.YPosition+m.Height)
}
// LineDown is a high performance command the moves the viewport up by a given
// number of lines. Use Model.LineDown to get the lines that should be
// rendered.
func LineUp(m Model, lines []string) tea.Cmd {
if len(lines) == 0 {
return nil
}
return tea.ScrollUp(lines, m.YPosition, m.YPosition+m.Height)
}
// UPDATE // UPDATE
// Update runs the update loop with default keybindings similar to popular // Update runs the update loop with default keybindings similar to popular
@ -318,14 +278,14 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case "d": case "d":
lines := m.HalfViewDown() lines := m.HalfViewDown()
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = HalfViewDown(m, lines) cmd = ViewDown(m, lines)
} }
// Up half page // Up half page
case "u": case "u":
lines := m.HalfViewUp() lines := m.HalfViewUp()
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = HalfViewUp(m, lines) cmd = ViewUp(m, lines)
} }
// Down one line // Down one line
@ -334,7 +294,7 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case "j": case "j":
lines := m.LineDown(1) lines := m.LineDown(1)
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = LineDown(m, lines) cmd = ViewDown(m, lines)
} }
// Up one line // Up one line
@ -343,7 +303,7 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case "k": case "k":
lines := m.LineUp(1) lines := m.LineUp(1)
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = LineUp(m, lines) cmd = ViewUp(m, lines)
} }
} }
@ -353,13 +313,13 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
case tea.MouseWheelUp: case tea.MouseWheelUp:
lines := m.LineUp(3) lines := m.LineUp(3)
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = LineUp(m, lines) cmd = ViewUp(m, lines)
} }
case tea.MouseWheelDown: case tea.MouseWheelDown:
lines := m.LineDown(3) lines := m.LineDown(3)
if m.HighPerformanceRendering { if m.HighPerformanceRendering {
cmd = LineDown(m, lines) cmd = ViewDown(m, lines)
} }
} }
} }