Repository: jesseduffield/lazygit
File: pkg/gui/files_panel.go (Go)

Code before:
		handleConfirm: func() error {
			cmdStr := gui.GitCommand.AmendHeadCmdStr()
			gui.OnRunCommand(oscommands.NewCmdLogEntry(cmdStr, gui.Tr.Spans.AmendCommit, true))
			return gui.withGpgHandling(cmdStr, gui.Tr.AmendingStatus, nil)
		},
	})
}

// handleCommitEditorPress - handle when the user wants to commit changes via
// their editor rather than via the popup panel
func (gui *Gui) handleCommitEditorPress() error {
	if gui.State.FileManager.GetItemsLength() == 0 {
		return gui.createErrorPanel(gui.Tr.NoFilesStagedTitle)
	}

	if len(gui.stagedFiles()) == 0 {
		return gui.promptToStageAllAndRetry(gui.handleCommitEditorPress)
	}

	return gui.runSubprocessWithSuspenseAndRefresh(
		gui.OSCommand.WithSpan(gui.Tr.Spans.Commit).PrepareSubProcess("git", "commit"),
	)
}

func (gui *Gui) handleStatusFilterPressed() error {
	menuItems := []*menuItem{}

	menuItems = append(menuItems, &menuItem{
		displayString: gui.Tr.FilterStagedFiles,
		onPress: func() error {
			return gui.setStatusFiltering(filetree.DisplayStaged)
		},
	})

	menuItems = append(menuItems, &menuItem{
		displayString: gui.Tr.FilterUnstagedFiles,
		onPress: func() error {
			return gui.setStatusFiltering(filetree.DisplayUnstaged)
		},
	})

	menuItems = append(menuItems, &menuItem{
		displayString: gui.Tr.ResetCommitFilterState,
		onPress: func() error {
			return gui.setStatusFiltering(filetree.DisplayAll)
		},
	})

	return gui.createMenu(gui.Tr.FilteringMenuTitle, menuItems, createMenuOptions{showCancel: false})
}


Review comment (suggestion):
because we're unconditionally appending these menu items, we can make this more expressive by going 
```go
	menuItems := []*menuItem{
		{
			displayString: gui.Tr.FilterStagedFiles,
			onPress: func() error {
				return gui.setStatusFiltering(filetree.DisplayStaged)
			},
		},
		{
			displayString: gui.Tr.FilterUnstagedFiles,
			onPress: func() error {
				return gui.setStatusFiltering(filetree.DisplayUnstaged)
			},
		},
		{
			displayString: gui.Tr.ResetCommitFilterState,
			onPress: func() error {
				return gui.setStatusFiltering(filetree.DisplayAll)
			},
		},
	}
```

Code after:
		handleConfirm: func() error {
			cmdStr := gui.GitCommand.AmendHeadCmdStr()
			gui.OnRunCommand(oscommands.NewCmdLogEntry(cmdStr, gui.Tr.Spans.AmendCommit, true))
			return gui.withGpgHandling(cmdStr, gui.Tr.AmendingStatus, nil)
		},
	})
}

// handleCommitEditorPress - handle when the user wants to commit changes via
// their editor rather than via the popup panel
func (gui *Gui) handleCommitEditorPress() error {
	if gui.State.FileManager.GetItemsLength() == 0 {
		return gui.createErrorPanel(gui.Tr.NoFilesStagedTitle)
	}

	if len(gui.stagedFiles()) == 0 {
		return gui.promptToStageAllAndRetry(gui.handleCommitEditorPress)
	}

	return gui.runSubprocessWithSuspenseAndRefresh(
		gui.OSCommand.WithSpan(gui.Tr.Spans.Commit).PrepareSubProcess("git", "commit"),
	)
}

func (gui *Gui) handleStatusFilterPressed() error {
	menuItems := []*menuItem{
		{
			displayString: gui.Tr.FilterStagedFiles,
			onPress: func() error {
				return gui.setStatusFiltering(filetree.DisplayStaged)
			},
		},
		{
			displayString: gui.Tr.FilterUnstagedFiles,
			onPress: func() error {
				return gui.setStatusFiltering(filetree.DisplayUnstaged)
			},
		},
		{
			displayString: gui.Tr.ResetCommitFilterState,
			onPress: func() error {
				return gui.setStatusFiltering(filetree.DisplayAll)
			},
		},
	}

	return gui.createMenu(gui.Tr.FilteringMenuTitle, menuItems, createMenuOptions{showCancel: true})
}

func (gui *Gui) setStatusFiltering(filter filetree.FileManagerDisplayFilter) error {
	state := gui.State