| 12345678910111213141516171819202122232425262728293031323334353637 |
- package editor
- import (
- "strings"
- "github.com/gdamore/tcell/v3"
- )
- func (m *Model) HandleKeyInput(ev *tcell.EventKey) {
- for _, action := range append(m.CurrentActionSet(), m.AM.Common...) {
- if action.Binding != "" && strings.ToLower(ev.Name()) == strings.ToLower(action.Binding) {
- if action.Command != "" && action.NeedsArgs == true {
- m.Mode = ModePalette
- m.BM.PaletteBuffer.Clear()
- m.BM.PaletteBuffer.Paste("/" + action.Command)
- return
- }
- action.Callback(m, []string{})
- return
- }
- }
- if m.Mode == ModeInsert {
- if ev.Key() == tcell.KeyRune {
- for _, r := range ev.Str() {
- m.BM.Current().Insert(r)
- }
- }
- }
- if m.Mode == ModePalette {
- if ev.Key() == tcell.KeyRune {
- for _, r := range ev.Str() {
- m.BM.PaletteBuffer.Insert(r)
- }
- }
- }
- }
|