UPDATE
(msg tea.Msg)
| 410 | // UPDATE |
| 411 | |
| 412 | func (m stashModel) update(msg tea.Msg) (stashModel, tea.Cmd) { |
| 413 | var cmds []tea.Cmd |
| 414 | |
| 415 | switch msg := msg.(type) { |
| 416 | case errMsg: |
| 417 | m.err = msg |
| 418 | |
| 419 | case localFileSearchFinished: |
| 420 | // We're finished searching for local files |
| 421 | m.loaded = true |
| 422 | |
| 423 | case filteredMarkdownMsg: |
| 424 | m.filteredMarkdowns = msg |
| 425 | m.setCursor(0) |
| 426 | return m, nil |
| 427 | |
| 428 | case spinner.TickMsg: |
| 429 | if m.shouldSpin() { |
| 430 | var cmd tea.Cmd |
| 431 | m.spinner, cmd = m.spinner.Update(msg) |
| 432 | cmds = append(cmds, cmd) |
| 433 | } |
| 434 | |
| 435 | case statusMessageTimeoutMsg: |
| 436 | if applicationContext(msg) == stashContext { |
| 437 | m.hideStatusMessage() |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | if m.filterState == filtering { |
| 442 | cmds = append(cmds, m.handleFiltering(msg)) |
| 443 | return m, tea.Batch(cmds...) |
| 444 | } |
| 445 | |
| 446 | // Updates per the current state |
| 447 | switch m.viewState { //nolint:exhaustive |
| 448 | case stashStateReady: |
| 449 | cmds = append(cmds, m.handleDocumentBrowsing(msg)) |
| 450 | case stashStateShowingError: |
| 451 | // Any key exists the error view |
| 452 | if _, ok := msg.(tea.KeyMsg); ok { |
| 453 | m.viewState = stashStateReady |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | return m, tea.Batch(cmds...) |
| 458 | } |
| 459 | |
| 460 | // Updates for when a user is browsing the markdown listing. |
| 461 | func (m *stashModel) handleDocumentBrowsing(msg tea.Msg) tea.Cmd { |
no test coverage detected