1
0

keyinput.go 789 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package editor
  2. import (
  3. "strings"
  4. "github.com/gdamore/tcell/v3"
  5. )
  6. func (m *Model) HandleKeyInput(ev *tcell.EventKey) {
  7. for _, action := range append(m.CurrentActionSet(), m.AM.Common...) {
  8. if action.Binding != "" && strings.ToLower(ev.Name()) == strings.ToLower(action.Binding) {
  9. if action.Command != "" && action.AskArgs == true {
  10. m.Mode = ModePalette
  11. m.BM.PaletteBuffer.Clear()
  12. m.BM.PaletteBuffer.Paste("/" + action.Command)
  13. return
  14. }
  15. action.Callback(m, []string{})
  16. return
  17. }
  18. }
  19. if m.Mode == ModeWrite {
  20. if ev.Key() == tcell.KeyRune {
  21. for _, r := range ev.Str() {
  22. m.BM.Current().Insert(r)
  23. }
  24. }
  25. }
  26. if m.Mode == ModePalette {
  27. if ev.Key() == tcell.KeyRune {
  28. for _, r := range ev.Str() {
  29. m.BM.PaletteBuffer.Insert(r)
  30. }
  31. }
  32. }
  33. }