keyinput.go 821 B

1234567891011121314151617181920212223242526272829303132333435
  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.Insert("/" + action.Command + " ")
  13. return
  14. } else if action.Command == "" && action.AskArgs == true {
  15. m.Mode = ModePalette
  16. }
  17. action.Callback(m, []string{})
  18. return
  19. }
  20. }
  21. if m.Mode == ModeWrite {
  22. if ev.Key() == tcell.KeyRune {
  23. m.BM.Current().Insert(ev.Str())
  24. }
  25. }
  26. if m.Mode == ModePalette {
  27. if ev.Key() == tcell.KeyRune {
  28. m.BM.PaletteBuffer.Insert(ev.Str())
  29. }
  30. }
  31. }