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

Method Update

src/internal/model.go:62–112  ·  view source on GitHub ↗

Update function for bubble tea to provide internal communication to the application

(msg tea.Msg)

Source from the content-addressed store, hash-verified

60// Update function for bubble tea to provide internal communication to the
61// application
62func (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
114func (m *model) handleMouseMsg(msg tea.MouseMsg) {
115 msgStr := msg.String()

Callers 9

updateComponentStateMethod · 0.80
TeaUpdateFunction · 0.80
SendDirectlyMethod · 0.80
HandleUpdateMethod · 0.80
handleNormalKeyInputMethod · 0.80
HandleUpdateMethod · 0.80
handleNormalKeyInputMethod · 0.80
UpdateStateMethod · 0.80
HandleTeaMsgMethod · 0.80

Calls 13

handleWindowResizeMethod · 0.95
handleMouseMsgMethod · 0.95
handleKeyInputMethod · 0.95
updateComponentStateMethod · 0.95
getMetadataCmdMethod · 0.95
UpdateStateMethod · 0.80
HandleTeaMsgMethod · 0.80
UpdatePreviewPanelMethod · 0.80
GetFilePreviewCmdMethod · 0.80
GetReqIDMethod · 0.65
ApplyMethod · 0.65

Tested by

no test coverage detected