Avoid potential variable capture situations

This commit is contained in:
Christian Rocha 2020-07-15 19:19:44 -04:00 committed by Christian Muehlhaeuser
commit 9263f82ebc
2 changed files with 22 additions and 27 deletions

View file

@ -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)
}

View file

@ -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 {