1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-17 12:06:38 +02:00

Always show the "Discard unchanged changes" menu item (#3683)

Always show the "Discard unchanged changes" menu item in the Discard
menu, just strike it through if not applicable. This will hopefully help
with confusion about the meaning of "all" in the "Discard all changes"
entry; some people misunderstand this to mean all changes in the working
copy. Seeing the "Discard unstaged changes" item next to it hopefully
makes it clearer that "all" is meant in contrast to that.
This commit is contained in:
Stefan Haller 2024-06-23 12:46:59 +02:00 committed by GitHub
commit a5620ebe3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 44 deletions

View File

@ -1062,60 +1062,65 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error {
selectedNodes = normalisedSelectedNodes(selectedNodes)
menuItems := []*types.MenuItem{
{
Label: self.c.Tr.DiscardAllChanges,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
discardAllChangesItem := types.MenuItem{
Label: self.c.Tr.DiscardAllChanges,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
if self.context().IsSelectingRange() {
defer self.context().CancelRangeSelect()
if self.context().IsSelectingRange() {
defer self.context().CancelRangeSelect()
}
for _, node := range selectedNodes {
if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil {
return err
}
}
for _, node := range selectedNodes {
if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil {
return err
}
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
},
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig.Keybinding.Files.ConfirmDiscard),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardAllTooltip,
map[string]string{
"path": self.formattedPaths(selectedNodes),
},
),
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
},
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig.Keybinding.Files.ConfirmDiscard),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardAllTooltip,
map[string]string{
"path": self.formattedPaths(selectedNodes),
},
),
}
if someNodesHaveStagedChanges(selectedNodes) && someNodesHaveUnstagedChanges(selectedNodes) {
menuItems = append(menuItems, &types.MenuItem{
Label: self.c.Tr.DiscardUnstagedChanges,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
discardUnstagedChangesItem := types.MenuItem{
Label: self.c.Tr.DiscardUnstagedChanges,
OnPress: func() error {
self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
if self.context().IsSelectingRange() {
defer self.context().CancelRangeSelect()
if self.context().IsSelectingRange() {
defer self.context().CancelRangeSelect()
}
for _, node := range selectedNodes {
if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil {
return err
}
}
for _, node := range selectedNodes {
if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil {
return err
}
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
},
Key: 'u',
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardUnstagedTooltip,
map[string]string{
"path": self.formattedPaths(selectedNodes),
},
Key: 'u',
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardUnstagedTooltip,
map[string]string{
"path": self.formattedPaths(selectedNodes),
},
),
})
),
}
if !someNodesHaveStagedChanges(selectedNodes) || !someNodesHaveUnstagedChanges(selectedNodes) {
discardUnstagedChangesItem.DisabledReason = &types.DisabledReason{Text: self.c.Tr.DiscardUnstagedDisabled}
}
menuItems := []*types.MenuItem{
&discardAllChangesItem,
&discardUnstagedChangesItem,
}
return self.c.Menu(types.CreateMenuOptions{Title: self.c.Tr.DiscardChangesTitle, Items: menuItems})

View File

@ -175,6 +175,7 @@ type TranslationSet struct {
UndoMergeResolveTooltip string
DiscardAllTooltip string
DiscardUnstagedTooltip string
DiscardUnstagedDisabled string
Pop string
StashPopTooltip string
Drop string
@ -1143,6 +1144,7 @@ func EnglishTranslationSet() TranslationSet {
UndoMergeResolveTooltip: "Undo last merge conflict resolution.",
DiscardAllTooltip: "Discard both staged and unstaged changes in '{{.path}}'.",
DiscardUnstagedTooltip: "Discard unstaged changes in '{{.path}}'.",
DiscardUnstagedDisabled: "The selected items don't have both staged and unstaged changes.",
Pop: "Pop",
StashPopTooltip: "Apply the stash entry to your working directory and remove the stash entry.",
Drop: "Drop",