Skip to content

Commit 3d703bc

Browse files
committed
Show hint about hunk staging mode being the default now, and how to switch to line mode
It is shown the first time the user enters either staging or patch building.
1 parent 37724e9 commit 3d703bc

File tree

6 files changed

+38
-4
lines changed

6 files changed

+38
-4
lines changed

pkg/app/entry_point.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
141141

142142
if integrationTest != nil {
143143
integrationTest.SetupConfig(appConfig)
144+
// Set this to true so that integration tests don't have to explicitly deal with the hunk
145+
// staging hint:
146+
appConfig.GetAppState().DidShowHunkStagingHint = true
144147

145148
// Preserve the changes that the test setup just made to the config, so
146149
// they don't get lost when we reload the config while running the test

pkg/config/app_config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,10 +656,11 @@ func (c *AppConfig) SaveGlobalUserConfig() {
656656
// AppState stores data between runs of the app like when the last update check
657657
// was performed and which other repos have been checked out
658658
type AppState struct {
659-
LastUpdateCheck int64
660-
RecentRepos []string
661-
StartupPopupVersion int
662-
LastVersion string // this is the last version the user was using, for the purpose of showing release notes
659+
LastUpdateCheck int64
660+
RecentRepos []string
661+
StartupPopupVersion int
662+
DidShowHunkStagingHint bool
663+
LastVersion string // this is the last version the user was using, for the purpose of showing release notes
663664

664665
// these are for shell commands typed in directly, not for custom commands in the lazygit config.
665666
// For backwards compatibility we keep the old name in yaml files.

pkg/gui/controllers/commits_files_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode
494494
}
495495

496496
self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts)
497+
self.c.Helpers().PatchBuilding.ShowHunkStagingHint()
498+
497499
return nil
498500
},
499501
})

pkg/gui/controllers/files_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error {
554554

555555
context := lo.Ternary(opts.ClickedWindowName == "secondary", self.c.Contexts().StagingSecondary, self.c.Contexts().Staging)
556556
self.c.Context().Push(context, opts)
557+
self.c.Helpers().PatchBuilding.ShowHunkStagingHint()
558+
557559
return nil
558560
}
559561

pkg/gui/controllers/helpers/patch_building_helper.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package helpers
22

33
import (
44
"errors"
5+
"fmt"
56

67
"github.com/jesseduffield/lazygit/pkg/commands/patch"
8+
"github.com/jesseduffield/lazygit/pkg/gui/keybindings"
79
"github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
810
"github.com/jesseduffield/lazygit/pkg/gui/types"
911
)
@@ -27,6 +29,19 @@ func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error)
2729
return true, nil
2830
}
2931

32+
func (self *PatchBuildingHelper) ShowHunkStagingHint() {
33+
if !self.c.AppState.DidShowHunkStagingHint && self.c.UserConfig().Gui.UseHunkModeInStagingView {
34+
self.c.AppState.DidShowHunkStagingHint = true
35+
self.c.SaveAppStateAndLogError()
36+
37+
message := fmt.Sprintf(self.c.Tr.HunkStagingHint,
38+
keybindings.Label(self.c.UserConfig().Keybinding.Main.ToggleSelectHunk))
39+
self.c.Confirm(types.ConfirmOpts{
40+
Prompt: message,
41+
})
42+
}
43+
}
44+
3045
// takes us from the patch building panel back to the commit files panel
3146
func (self *PatchBuildingHelper) Escape() {
3247
self.c.Context().Pop()

pkg/i18n/english.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ type TranslationSet struct {
292292
SelectHunk string
293293
SelectLineByLine string
294294
ToggleSelectHunkTooltip string
295+
HunkStagingHint string
295296
ToggleSelectionForPatch string
296297
EditHunk string
297298
EditHunkTooltip string
@@ -1059,6 +1060,15 @@ const englishNonReloadableConfigWarning = `The following config settings were ch
10591060
10601061
{{configs}}`
10611062

1063+
const englishHunkStagingHint = `Hunk selection mode is now the default for staging. If you want to stage individual lines, press '%s' to switch to line-by-line mode.
1064+
1065+
If you prefer to use line-by-line mode by default (like in earlier lazygit versions), add
1066+
1067+
gui:
1068+
useHunkModeInStagingView: false
1069+
1070+
to your lazygit config.`
1071+
10621072
// exporting this so we can use it in tests
10631073
func EnglishTranslationSet() *TranslationSet {
10641074
return &TranslationSet{
@@ -1342,6 +1352,7 @@ func EnglishTranslationSet() *TranslationSet {
13421352
SelectHunk: "Select hunks",
13431353
SelectLineByLine: "Select line-by-line",
13441354
ToggleSelectHunkTooltip: "Toggle line-by-line vs. hunk selection mode.",
1355+
HunkStagingHint: englishHunkStagingHint,
13451356
ToggleSelectionForPatch: `Toggle lines in patch`,
13461357
EditHunk: `Edit hunk`,
13471358
EditHunkTooltip: "Edit selected hunk in external editor.",

0 commit comments

Comments
 (0)