From dbb1d939701375ddaf48e4e81c2344d0c4286d9d Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 17 Jul 2020 18:22:51 -0400 Subject: [PATCH] Remove redundant viewport commands --- viewport/viewport.go | 62 ++++++++------------------------------------ 1 file changed, 11 insertions(+), 51 deletions(-) diff --git a/viewport/viewport.go b/viewport/viewport.go index 0aa9015..6b34707 100644 --- a/viewport/viewport.go +++ b/viewport/viewport.go @@ -218,9 +218,9 @@ func Sync(m Model) tea.Cmd { ) } -// ViewDown is a high performance command that moves the viewport up by one -// viewport height. Use Model.ViewDown to get the lines that should be -// rendered. For example: +// ViewDown is a high performance command that moves the viewport up by a given +// numer of lines. Use Model.ViewDown to get the lines that should be rendered. +// For example: // // lines := model.ViewDown(1) // 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) } -// ViewUp is a high performance command the moves the viewport down by one -// viewport height. Use Model.ViewDown to get the lines that should be +// ViewUp is a high performance command the moves the viewport down by a given +// number of lines height. Use Model.ViewDown to get the lines that should be // rendered. func ViewUp(m Model, lines []string) tea.Cmd { 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) } -// 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 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": lines := m.HalfViewDown() if m.HighPerformanceRendering { - cmd = HalfViewDown(m, lines) + cmd = ViewDown(m, lines) } // Up half page case "u": lines := m.HalfViewUp() if m.HighPerformanceRendering { - cmd = HalfViewUp(m, lines) + cmd = ViewUp(m, lines) } // Down one line @@ -334,7 +294,7 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) { case "j": lines := m.LineDown(1) if m.HighPerformanceRendering { - cmd = LineDown(m, lines) + cmd = ViewDown(m, lines) } // Up one line @@ -343,7 +303,7 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) { case "k": lines := m.LineUp(1) 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: lines := m.LineUp(3) if m.HighPerformanceRendering { - cmd = LineUp(m, lines) + cmd = ViewUp(m, lines) } case tea.MouseWheelDown: lines := m.LineDown(3) if m.HighPerformanceRendering { - cmd = LineDown(m, lines) + cmd = ViewDown(m, lines) } } }