Identify the current state of the application m and properly handle the msg keybind pressed
(msg tea.KeyPressMsg)
| 272 | // Identify the current state of the application m and properly handle the |
| 273 | // msg keybind pressed |
| 274 | func (m *model) handleKeyInput(msg tea.KeyPressMsg) tea.Cmd { |
| 275 | slog.Debug("model.handleKeyInput", "msg", msg, "typestr", msg.String(), |
| 276 | "code", msg.Code, "text", msg.Text, "mod", msg.Mod) |
| 277 | slog.Debug("model.handleKeyInput. model info. ", |
| 278 | "fileModel.FocusedPanelIndex", m.fileModel.FocusedPanelIndex, |
| 279 | "filePanel.isFocused", m.getFocusedFilePanel().IsFocused, |
| 280 | "filePanel.panelMode", m.getFocusedFilePanel().PanelMode, |
| 281 | "typingModal.open", m.typingModal.open, |
| 282 | "notifyModel.open", m.notifyModel.IsOpen(), |
| 283 | "promptModal.open", m.promptModal.IsOpen(), |
| 284 | "fileModel.renaming", m.fileModel.Renaming, |
| 285 | "searchBar.focused", m.getFocusedFilePanel().SearchBar.Focused(), |
| 286 | "helpMenu.open", m.helpMenu.IsOpen(), |
| 287 | "firstTextInput", m.firstTextInput, |
| 288 | "focusPanel", m.focusPanel, |
| 289 | ) |
| 290 | if m.firstUse { |
| 291 | m.firstUse = false |
| 292 | return nil |
| 293 | } |
| 294 | var cmd tea.Cmd |
| 295 | cdOnQuit := common.Config.CdOnQuit |
| 296 | switch { |
| 297 | case m.spfError.IsOpen(): |
| 298 | cmd = m.spfErrorModelOpenKey(msg.String()) |
| 299 | case m.typingModal.open: |
| 300 | m.typingModalOpenKey(msg.String()) |
| 301 | case m.promptModal.IsOpen(): |
| 302 | // Ignore keypress. It will be handled in Update call via |
| 303 | // updateFilePanelState |
| 304 | // TODO: Convert that to async via tea.Cmd |
| 305 | case m.zoxideModal.IsOpen(): |
| 306 | // Ignore keypress. It will be handled in Update call via |
| 307 | // updateFilePanelState |
| 308 | |
| 309 | // Handles all warn models except the warn model for confirming to quit |
| 310 | case m.notifyModel.IsOpen(): |
| 311 | cmd = m.notifyModelOpenKey(msg.String()) |
| 312 | |
| 313 | // If renaming a object |
| 314 | case m.fileModel.Renaming: |
| 315 | cmd = m.renamingKey(msg.String()) |
| 316 | case m.sidebarModel.IsRenaming(): |
| 317 | m.sidebarRenamingKey(msg.String()) |
| 318 | // If search bar is open |
| 319 | case m.getFocusedFilePanel().SearchBar.Focused(): |
| 320 | m.focusOnSearchbarKey(msg.String()) |
| 321 | // If sort options menu is open |
| 322 | case m.sidebarModel.SearchBarFocused(): |
| 323 | m.sidebarModel.HandleSearchBarKey(msg.String()) |
| 324 | case m.sortModal.IsOpen(): |
| 325 | m.sortOptionsKey(msg.String()) |
| 326 | // If help menu is open |
| 327 | case m.helpMenu.IsOpen(): |
| 328 | m.helpMenu.HandleKey(msg.String()) |
| 329 | |
| 330 | case slices.Contains(common.Hotkeys.Quit, msg.String()): |
| 331 | m.modelQuitState = quitInitiated |