Gim/internal/editor/update.go
Hayden Hargreaves 774d0d0071 feat: implement scroll actions, tested
This is control+d and control+u
2026-02-18 18:09:19 -07:00

30 lines
565 B
Go

package editor
import (
tea "github.com/charmbracelet/bubbletea"
)
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.win_h = msg.Height
m.win_w = msg.Width
case tea.KeyMsg:
// TODO: This needs to be removed, but for now its required for the tests.
// Ctrl+C always quits regardless of mode
if msg.Type == tea.KeyCtrlC {
return m, tea.Quit
}
cmd = m.input.Handle(&m, msg.String())
}
// Keep cursor in view after any update
m.AdjustScroll()
return m, cmd
}