HandleKeyboardEvents does that
(m *TuiModel, msg *tea.KeyMsg)
| 111 | |
| 112 | // HandleKeyboardEvents does that |
| 113 | func HandleKeyboardEvents(m *TuiModel, msg *tea.KeyMsg) tea.Cmd { |
| 114 | var ( |
| 115 | cmd tea.Cmd |
| 116 | ) |
| 117 | str := msg.String() |
| 118 | |
| 119 | if m.UI.EditModeEnabled { // handle edit mode |
| 120 | HandleEditMode(m, str) |
| 121 | return nil |
| 122 | } else if m.UI.FormatModeEnabled { |
| 123 | if str == "esc" { // cycle focus |
| 124 | if m.TextInput.Model.Focused() { |
| 125 | cmd = m.FormatInput.Model.FocusCommand() |
| 126 | m.TextInput.Model.Blur() |
| 127 | } else { |
| 128 | cmd = m.TextInput.Model.FocusCommand() |
| 129 | m.FormatInput.Model.Blur() |
| 130 | } |
| 131 | return cmd |
| 132 | } |
| 133 | |
| 134 | if m.TextInput.Model.Focused() { |
| 135 | HandleEditMode(m, str) |
| 136 | } else { |
| 137 | HandleFormatMode(m, str) |
| 138 | } |
| 139 | |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | for k := range GlobalCommands { |
| 144 | if str == k { |
| 145 | return GlobalCommands[str](m) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return nil |
| 150 | } |
no test coverage detected