createNavigationInputCapture creates a common input capture handler for navigation between components.
(app *App, leftTarget, rightTarget tview.Primitive)
| 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 { |
| 50 | return func(event *tcell.EventKey) *tcell.EventKey { |
| 51 | switch event.Key() { |
| 52 | case tcell.KeyLeft: |
| 53 | if app != nil && leftTarget != nil { |
| 54 | app.SetFocus(leftTarget) |
| 55 | |
| 56 | return nil |
| 57 | } |
| 58 | case tcell.KeyRight: |
| 59 | if app != nil && rightTarget != nil { |
| 60 | app.SetFocus(rightTarget) |
| 61 | |
| 62 | return nil |
| 63 | } |
| 64 | case tcell.KeyRune: |
| 65 | switch event.Rune() { |
| 66 | case 'h': // VI-like left navigation |
| 67 | if app != nil && leftTarget != nil { |
| 68 | app.SetFocus(leftTarget) |
| 69 | |
| 70 | return nil |
| 71 | } |
| 72 | case 'l': // VI-like right navigation |
| 73 | if app != nil && rightTarget != nil { |
| 74 | app.SetFocus(rightTarget) |
| 75 | |
| 76 | return nil |
| 77 | } |
| 78 | case 'j': // VI-like down navigation |
| 79 | // Let the component handle down navigation naturally |
| 80 | return tcell.NewEventKey(tcell.KeyDown, 0, tcell.ModNone) |
| 81 | case 'k': // VI-like up navigation |
| 82 | // Let the component handle up navigation naturally |
| 83 | return tcell.NewEventKey(tcell.KeyUp, 0, tcell.ModNone) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return event |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // SetHotkeyOverride installs a temporary handler that runs before global shortcuts. |
| 92 | // Return nil from the handler to swallow the event; otherwise return the event |