MCPcopy
hub / github.com/yorukot/superfile / handleKeyInput

Method handleKeyInput

src/internal/model.go:274–358  ·  view source on GitHub ↗

Identify the current state of the application m and properly handle the msg keybind pressed

(msg tea.KeyPressMsg)

Source from the content-addressed store, hash-verified

272// Identify the current state of the application m and properly handle the
273// msg keybind pressed
274func (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

Callers 2

UpdateMethod · 0.95

Calls 15

getFocusedFilePanelMethod · 0.95
spfErrorModelOpenKeyMethod · 0.95
typingModalOpenKeyMethod · 0.95
notifyModelOpenKeyMethod · 0.95
renamingKeyMethod · 0.95
sidebarRenamingKeyMethod · 0.95
focusOnSearchbarKeyMethod · 0.95
sortOptionsKeyMethod · 0.95
mainKeyMethod · 0.95
warnModalForQuitMethod · 0.95
quitSuperfileMethod · 0.95
IsRenamingMethod · 0.80

Tested by 1