Skip to content

Commit

Permalink
fix(ui): move support goto top/bottom in viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 11, 2023
1 parent 3c9b7df commit e617c8d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
11 changes: 1 addition & 10 deletions server/ui/components/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions server/ui/components/viewport/viewport.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/ui/pages/repo/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -151,6 +153,8 @@ func (l *Log) FullHelp() [][]key.Binding {
{
k.Down,
k.Up,
l.common.KeyMap.GotoTop,
l.common.KeyMap.GotoBottom,
},
}...)
}
Expand Down

0 comments on commit e617c8d

Please sign in to comment.