diff options
author | Christian Rocha <christian@rocha.is> | 2020-07-15 19:19:44 -0400 |
---|---|---|
committer | Christian Muehlhaeuser <muesli@gmail.com> | 2020-10-05 13:50:04 +0200 |
commit | 9263f82ebc7face06318865eaa00773226539736 (patch) | |
tree | 859b98cee02c3876f08c993c78d873ae0f8aac5d /ui | |
parent | 091c3be039546939104e86c84170e1fd72cd8425 (diff) |
Avoid potential variable capture situations
Diffstat (limited to 'ui')
-rw-r--r-- | ui/stash.go | 22 | ||||
-rw-r--r-- | ui/ui.go | 27 |
2 files changed, 22 insertions, 27 deletions
diff --git a/ui/stash.go b/ui/stash.go index c8bd457..83d6f35 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -199,10 +199,7 @@ func newStashModel() stashModel { // UPDATE func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { - var ( - cmd tea.Cmd - cmds []tea.Cmd - ) + var cmds []tea.Cmd switch msg := msg.(type) { @@ -239,7 +236,8 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { case spinner.TickMsg: if !m.loaded.done() || m.loadingFromNetwork || m.state == stashStateLoadingDocument { - m.spinner, cmd = spinner.Update(msg, m.spinner) + newSpinnerModel, cmd := spinner.Update(msg, m.spinner) + m.spinner = newSpinnerModel cmds = append(cmds, cmd) } @@ -297,12 +295,12 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { md := m.selectedMarkdown() if md.markdownType == localFile { - cmd = loadLocalMarkdown(md) + cmds = append(cmds, loadLocalMarkdown(md)) } else { - cmd = loadRemoteMarkdown(m.cc, md.ID, md.markdownType) + cmds = append(cmds, loadRemoteMarkdown(m.cc, md.ID, md.markdownType)) } - cmds = append(cmds, cmd, spinner.Tick(m.spinner)) + cmds = append(cmds, spinner.Tick(m.spinner)) // Set note case "m": @@ -331,7 +329,8 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { } // Update paginator - m.paginator, cmd = paginator.Update(msg, m.paginator) + newPaginatorModel, cmd := paginator.Update(msg, m.paginator) + m.paginator = newPaginatorModel cmds = append(cmds, cmd) // Keep the index in bounds when paginating @@ -390,7 +389,7 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { // Set new note md := m.selectedMarkdown() newNote := m.noteInput.Value() - cmd = saveDocumentNote(m.cc, md.ID, newNote) + cmd := saveDocumentNote(m.cc, md.ID, newNote) md.Note = newNote m.noteInput.Reset() m.state = stashStateReady @@ -399,7 +398,8 @@ func stashUpdate(msg tea.Msg, m stashModel) (stashModel, tea.Cmd) { } // Update the text input component used to set notes - m.noteInput, cmd = textinput.Update(msg, m.noteInput) + newNoteInputModel, cmd := textinput.Update(msg, m.noteInput) + m.noteInput = newNoteInputModel cmds = append(cmds, cmd) } @@ -157,13 +157,9 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) { } } - var ( - cmd tea.Cmd - cmds []tea.Cmd - ) + var cmds []tea.Cmd switch msg := msg.(type) { - case tea.KeyMsg: switch msg.String() { case "q": @@ -185,24 +181,24 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) { // Special cases for the pager case stateShowDocument: - var cmds []tea.Cmd + var batch []tea.Cmd if m.pager.state == pagerStateBrowse { // If the user is just browing a document, exit the pager. m.unloadDocument() if m.pager.viewport.HighPerformanceRendering { - cmds = append(cmds, tea.ClearScrollArea) + batch = append(batch, tea.ClearScrollArea) } if !m.stash.loaded.done() || m.stash.loadingFromNetwork { - cmds = append(cmds, spinner.Tick(m.stash.spinner)) + batch = append(batch, spinner.Tick(m.stash.spinner)) } } else { // Otherwise send these key messages through to pager for // processing newPagerModel, cmd := pagerUpdate(msg, m.pager) m.pager = newPagerModel - cmds = append(cmds, cmd) + cmds = append(batch, cmd) } - return m, tea.Batch(cmds...) + return m, tea.Batch(batch...) } return m, tea.Quit @@ -309,11 +305,13 @@ func update(msg tea.Msg, mdl tea.Model) (tea.Model, tea.Cmd) { switch m.state { case stateShowStash: - m.stash, cmd = stashUpdate(msg, m.stash) + newStashModel, cmd := stashUpdate(msg, m.stash) + m.stash = newStashModel cmds = append(cmds, cmd) case stateShowDocument: - m.pager, cmd = pagerUpdate(msg, m.pager) + newPagerModel, cmd := pagerUpdate(msg, m.pager) + m.pager = newPagerModel cmds = append(cmds, cmd) } @@ -365,10 +363,7 @@ func findLocalFiles() tea.Msg { } ch := gitcha.FindFileFromList(cwd, []string{"*.md"}) - return initLocalFileSearchMsg{ - ch: ch, - cwd: cwd, - } + return initLocalFileSearchMsg{ch: ch, cwd: cwd} } func findNextLocalFile(m model) tea.Cmd { |