Update function for bubble tea to provide internal communication to the application
(msg tea.Msg)
| 60 | // Update function for bubble tea to provide internal communication to the |
| 61 | // application |
| 62 | func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { |
| 63 | slog.Debug("model.Update() called", "msgType", reflect.TypeOf(msg)) |
| 64 | |
| 65 | var sidebarCmd, inputCmd, updateCmd, panelCmd, |
| 66 | metadataCmd, filePreviewCmd, helpMenuCmd, resizeCmd tea.Cmd |
| 67 | |
| 68 | // These are above the key message handing to prevent issues with firstKeyInput |
| 69 | // if someone presses `/` to focus to searchBar, searchBar will otherwise |
| 70 | // get `/` input too. |
| 71 | sidebarCmd = m.sidebarModel.UpdateState(msg) |
| 72 | // Necessary for blinking. Can't do this in HandleKey, as we only pass KeyMsg there |
| 73 | helpMenuCmd = m.helpMenu.HandleTeaMsg(msg) |
| 74 | |
| 75 | switch msg := msg.(type) { |
| 76 | case tea.WindowSizeMsg: |
| 77 | resizeCmd = m.handleWindowResize(msg) |
| 78 | case tea.MouseMsg: |
| 79 | m.handleMouseMsg(msg) |
| 80 | case tea.KeyPressMsg: |
| 81 | inputCmd = m.handleKeyInput(msg) |
| 82 | |
| 83 | // Has to handle zoxide messages separately as they could be generated via |
| 84 | // zoxide update commands, or batched commands from textinput |
| 85 | // Cannot do it like processbar messages |
| 86 | case zoxideui.UpdateMsg: |
| 87 | slog.Debug("Got ModelUpdate message", "id", msg.GetReqID()) |
| 88 | updateCmd = msg.Apply(&m.zoxideModal) |
| 89 | |
| 90 | // Its a pain to interconvert commands like processBar |
| 91 | case preview.UpdateMsg: |
| 92 | slog.Debug("Got ModelUpdate message", "id", msg.GetReqID()) |
| 93 | updateCmd = m.fileModel.UpdatePreviewPanel(msg) |
| 94 | case ModelUpdateMessage: |
| 95 | slog.Debug("Got ModelUpdate message", "id", msg.GetReqID()) |
| 96 | updateCmd = msg.ApplyToModel(m) |
| 97 | |
| 98 | default: |
| 99 | slog.Debug("Message of type that is not explicitly handled") |
| 100 | } |
| 101 | |
| 102 | // This is needed for blink, etc to work |
| 103 | panelCmd = m.updateComponentState(msg) |
| 104 | |
| 105 | m.updateModelStateAfterMsg() |
| 106 | filePreviewCmd = m.fileModel.GetFilePreviewCmd(false) |
| 107 | |
| 108 | metadataCmd = m.getMetadataCmd() |
| 109 | |
| 110 | return m, tea.Batch(sidebarCmd, helpMenuCmd, inputCmd, updateCmd, |
| 111 | panelCmd, metadataCmd, filePreviewCmd, resizeCmd) |
| 112 | } |
| 113 | |
| 114 | func (m *model) handleMouseMsg(msg tea.MouseMsg) { |
| 115 | msgStr := msg.String() |
no test coverage detected