keyinput.go 775 B

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