update.go 667 B

1234567891011121314151617181920212223242526
  1. package tui
  2. import (
  3. tea "charm.land/bubbletea/v2"
  4. )
  5. func (m EditorModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
  6. switch msg := msg.(type) {
  7. case tea.WindowSizeMsg:
  8. m.Width = msg.Width
  9. m.Height = msg.Height
  10. m.Viewport.Width = msg.Width
  11. m.Viewport.Height = msg.Height - 2 // Space for footer status bar
  12. return m, nil
  13. case tea.KeyMsg:
  14. switch msg.String() {
  15. case "ctrl+c":
  16. return m, tea.Quit
  17. default:
  18. m.Document.Table.Insert(msg.String(), m.Document.Table.Size())
  19. m.Viewport.SetContent(m.RenderBufferToString())
  20. }
  21. }
  22. return m, nil
  23. }