Update is where all commands and whatnot get processed
(message tea.Msg)
| 65 | |
| 66 | // Update is where all commands and whatnot get processed |
| 67 | func (m TuiModel) Update(message tea.Msg) (tea.Model, tea.Cmd) { |
| 68 | var ( |
| 69 | command tea.Cmd |
| 70 | commands []tea.Cmd |
| 71 | ) |
| 72 | |
| 73 | if !m.UI.FormatModeEnabled { |
| 74 | m.Viewport, _ = m.Viewport.Update(message) |
| 75 | } |
| 76 | |
| 77 | switch msg := message.(type) { |
| 78 | case list.FilterMatchesMessage: |
| 79 | m.ClipboardList, command = m.ClipboardList.Update(msg) |
| 80 | break |
| 81 | case tea.MouseMsg: |
| 82 | HandleMouseEvents(&m, &msg) |
| 83 | m.SetViewSlices() |
| 84 | break |
| 85 | case tea.WindowSizeMsg: |
| 86 | event := HandleWindowSizeEvents(&m, &msg) |
| 87 | if event != nil { |
| 88 | commands = append(commands, event) |
| 89 | } |
| 90 | break |
| 91 | case tea.KeyMsg: |
| 92 | str := msg.String() |
| 93 | if m.UI.ShowClipboard { |
| 94 | HandleClipboardEvents(&m, str, &command, msg) |
| 95 | break |
| 96 | } |
| 97 | |
| 98 | // when fullscreen selection viewing is in session, don't allow UI manipulation other than quit or exit |
| 99 | s := msg.String() |
| 100 | invalidRenderCommand := m.UI.RenderSelection && |
| 101 | s != "esc" && |
| 102 | s != "ctrl+c" && |
| 103 | s != "q" && |
| 104 | s != "p" && |
| 105 | s != "m" && |
| 106 | s != "n" |
| 107 | if invalidRenderCommand { |
| 108 | break |
| 109 | } |
| 110 | |
| 111 | if s == "ctrl+c" || (s == "q" && (!m.UI.EditModeEnabled && !m.UI.FormatModeEnabled)) { |
| 112 | return m, tea.Quit |
| 113 | } |
| 114 | |
| 115 | event := HandleKeyboardEvents(&m, &msg) |
| 116 | if event != nil { |
| 117 | commands = append(commands, event) |
| 118 | } |
| 119 | if !m.UI.EditModeEnabled && m.Ready { |
| 120 | m.SetViewSlices() |
| 121 | if m.UI.FormatModeEnabled { |
| 122 | MoveCursorWithinBounds(&m) |
| 123 | } |
| 124 | } |
nothing calls this directly
no test coverage detected