From 3ef755e33b8df51b6d0bfa930e33a8e4e2c23975 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 10 May 2023 17:06:55 -0400 Subject: [PATCH] fix(ui): move support goto top/bottom in viewport --- server/ui/components/code/code.go | 11 +---------- server/ui/components/viewport/viewport.go | 10 ++++++++++ server/ui/pages/repo/log.go | 4 ++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/server/ui/components/code/code.go b/server/ui/components/code/code.go index bf3fc4c4d..829118334 100644 --- a/server/ui/components/code/code.go +++ b/server/ui/components/code/code.go @@ -6,7 +6,6 @@ import ( "sync" "github.com/alecthomas/chroma/lexers" - "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/glamour" gansi "github.com/charmbracelet/glamour/ansi" @@ -99,18 +98,10 @@ func (r *Code) Init() tea.Cmd { // Update implements tea.Model. func (r *Code) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds := make([]tea.Cmd, 0) - switch msg := msg.(type) { + switch msg.(type) { case tea.WindowSizeMsg: // Recalculate content width and line wrap. cmds = append(cmds, r.Init()) - case tea.KeyMsg: - // Viewport doesn't handle these keys, so we do it here. - switch { - case key.Matches(msg, r.common.KeyMap.GotoTop): - r.GotoTop() - case key.Matches(msg, r.common.KeyMap.GotoBottom): - r.GotoBottom() - } } v, cmd := r.Viewport.Update(msg) r.Viewport = v.(*vp.Viewport) diff --git a/server/ui/components/viewport/viewport.go b/server/ui/components/viewport/viewport.go index bdccc0f0a..35fe8f24d 100644 --- a/server/ui/components/viewport/viewport.go +++ b/server/ui/components/viewport/viewport.go @@ -1,6 +1,7 @@ package viewport import ( + "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/soft-serve/server/ui/common" @@ -36,6 +37,15 @@ func (v *Viewport) Init() tea.Cmd { // Update implements tea.Model. func (v *Viewport) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + switch { + case key.Matches(msg, v.common.KeyMap.GotoTop): + v.GotoTop() + case key.Matches(msg, v.common.KeyMap.GotoBottom): + v.GotoBottom() + } + } vp, cmd := v.Model.Update(msg) v.Model = &vp return v, cmd diff --git a/server/ui/pages/repo/log.go b/server/ui/pages/repo/log.go index 0b1480b46..21bbcdf9f 100644 --- a/server/ui/pages/repo/log.go +++ b/server/ui/pages/repo/log.go @@ -105,6 +105,8 @@ func (l *Log) ShortHelp() []key.Binding { return []key.Binding{ l.common.KeyMap.UpDown, l.common.KeyMap.BackItem, + l.common.KeyMap.GotoTop, + l.common.KeyMap.GotoBottom, } default: return []key.Binding{} @@ -151,6 +153,8 @@ func (l *Log) FullHelp() [][]key.Binding { { k.Down, k.Up, + l.common.KeyMap.GotoTop, + l.common.KeyMap.GotoBottom, }, }...) }