keyMatch checks if an event matches a key specification string.
(ev *tcell.EventKey, spec string)
| 15 | |
| 16 | // keyMatch checks if an event matches a key specification string. |
| 17 | func keyMatch(ev *tcell.EventKey, spec string) bool { |
| 18 | if strings.TrimSpace(spec) == "" { |
| 19 | return false |
| 20 | } |
| 21 | |
| 22 | key, r, mod, err := keys.Parse(spec) |
| 23 | if err != nil { |
| 24 | if config.DebugEnabled { |
| 25 | models.GetUILogger().Debug("invalid key spec %s: %v", spec, err) |
| 26 | } |
| 27 | |
| 28 | return false |
| 29 | } |
| 30 | |
| 31 | evKey, evRune, evMod := keys.NormalizeEvent(ev) |
| 32 | |
| 33 | if evMod != mod { |
| 34 | return false |
| 35 | } |
| 36 | |
| 37 | if key == tcell.KeyRune { |
| 38 | match := evKey == tcell.KeyRune && r != 0 && strings.EqualFold(string(evRune), string(r)) |
| 39 | |
| 40 | return match |
| 41 | } |
| 42 | |
| 43 | match := evKey == key |
| 44 | |
| 45 | return match |
| 46 | } |
| 47 | |
| 48 | // createNavigationInputCapture creates a common input capture handler for navigation between components. |
| 49 | func createNavigationInputCapture(app *App, leftTarget, rightTarget tview.Primitive) func(*tcell.EventKey) *tcell.EventKey { |