Updates for when a user is in the filter editing interface.
(msg tea.Msg)
| 599 | |
| 600 | // Updates for when a user is in the filter editing interface. |
| 601 | func (m *stashModel) handleFiltering(msg tea.Msg) tea.Cmd { |
| 602 | var cmds []tea.Cmd |
| 603 | |
| 604 | // Handle keys |
| 605 | if msg, ok := msg.(tea.KeyMsg); ok { //nolint:nestif |
| 606 | switch msg.String() { |
| 607 | case keyEsc: |
| 608 | // Cancel filtering |
| 609 | m.resetFiltering() |
| 610 | case keyEnter, "tab", "shift+tab", "ctrl+k", "up", "ctrl+j", "down": |
| 611 | m.hideStatusMessage() |
| 612 | |
| 613 | if len(m.markdowns) == 0 { |
| 614 | break |
| 615 | } |
| 616 | |
| 617 | h := m.getVisibleMarkdowns() |
| 618 | |
| 619 | // If we've filtered down to nothing, clear the filter |
| 620 | if len(h) == 0 { |
| 621 | m.viewState = stashStateReady |
| 622 | m.resetFiltering() |
| 623 | break |
| 624 | } |
| 625 | |
| 626 | // When there's only one filtered markdown left we can just |
| 627 | // "open" it directly |
| 628 | if len(h) == 1 { |
| 629 | m.viewState = stashStateReady |
| 630 | m.resetFiltering() |
| 631 | cmds = append(cmds, m.openMarkdown(h[0])) |
| 632 | break |
| 633 | } |
| 634 | |
| 635 | // Add new section if it's not present |
| 636 | if m.sections[len(m.sections)-1].key != filterSection { |
| 637 | m.sections = append(m.sections, sections[filterSection]) |
| 638 | } |
| 639 | m.sectionIndex = len(m.sections) - 1 |
| 640 | |
| 641 | m.filterInput.Blur() |
| 642 | |
| 643 | m.filterState = filterApplied |
| 644 | if m.filterInput.Value() == "" { |
| 645 | m.resetFiltering() |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | // Update the filter text input component |
| 651 | newFilterInputModel, inputCmd := m.filterInput.Update(msg) |
| 652 | currentFilterVal := m.filterInput.Value() |
| 653 | newFilterVal := newFilterInputModel.Value() |
| 654 | m.filterInput = newFilterInputModel |
| 655 | cmds = append(cmds, inputCmd) |
| 656 | |
| 657 | // If the filtering input has changed, request updated filtering |
| 658 | if newFilterVal != currentFilterVal { |
no test coverage detected