From 3d703bc9b9d548a9c9c67e0eeac2302a96e6ccbe Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 28 Jul 2025 18:03:27 +0200 Subject: [PATCH] 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. --- pkg/app/entry_point.go | 3 +++ pkg/config/app_config.go | 9 +++++---- pkg/gui/controllers/commits_files_controller.go | 2 ++ pkg/gui/controllers/files_controller.go | 2 ++ .../controllers/helpers/patch_building_helper.go | 15 +++++++++++++++ pkg/i18n/english.go | 11 +++++++++++ 6 files changed, 38 insertions(+), 4 deletions(-) diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index 498abc7fe..2b683707c 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -141,6 +141,9 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes if integrationTest != nil { integrationTest.SetupConfig(appConfig) + // Set this to true so that integration tests don't have to explicitly deal with the hunk + // staging hint: + appConfig.GetAppState().DidShowHunkStagingHint = true // Preserve the changes that the test setup just made to the config, so // they don't get lost when we reload the config while running the test diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 24db0ab6c..ba1252b6e 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -656,10 +656,11 @@ func (c *AppConfig) SaveGlobalUserConfig() { // AppState stores data between runs of the app like when the last update check // was performed and which other repos have been checked out type AppState struct { - LastUpdateCheck int64 - RecentRepos []string - StartupPopupVersion int - LastVersion string // this is the last version the user was using, for the purpose of showing release notes + LastUpdateCheck int64 + RecentRepos []string + StartupPopupVersion int + DidShowHunkStagingHint bool + LastVersion string // this is the last version the user was using, for the purpose of showing release notes // these are for shell commands typed in directly, not for custom commands in the lazygit config. // For backwards compatibility we keep the old name in yaml files. diff --git a/pkg/gui/controllers/commits_files_controller.go b/pkg/gui/controllers/commits_files_controller.go index 02cc67eae..45bfa5f0b 100644 --- a/pkg/gui/controllers/commits_files_controller.go +++ b/pkg/gui/controllers/commits_files_controller.go @@ -494,6 +494,8 @@ func (self *CommitFilesController) enterCommitFile(node *filetree.CommitFileNode } self.c.Context().Push(self.c.Contexts().CustomPatchBuilder, opts) + self.c.Helpers().PatchBuilding.ShowHunkStagingHint() + return nil }, }) diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 20567a510..69b4865ef 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -554,6 +554,8 @@ func (self *FilesController) EnterFile(opts types.OnFocusOpts) error { context := lo.Ternary(opts.ClickedWindowName == "secondary", self.c.Contexts().StagingSecondary, self.c.Contexts().Staging) self.c.Context().Push(context, opts) + self.c.Helpers().PatchBuilding.ShowHunkStagingHint() + return nil } diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index c69435954..72ece0a71 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -2,8 +2,10 @@ package helpers import ( "errors" + "fmt" "github.com/jesseduffield/lazygit/pkg/commands/patch" + "github.com/jesseduffield/lazygit/pkg/gui/keybindings" "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -27,6 +29,19 @@ func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) return true, nil } +func (self *PatchBuildingHelper) ShowHunkStagingHint() { + if !self.c.AppState.DidShowHunkStagingHint && self.c.UserConfig().Gui.UseHunkModeInStagingView { + self.c.AppState.DidShowHunkStagingHint = true + self.c.SaveAppStateAndLogError() + + message := fmt.Sprintf(self.c.Tr.HunkStagingHint, + keybindings.Label(self.c.UserConfig().Keybinding.Main.ToggleSelectHunk)) + self.c.Confirm(types.ConfirmOpts{ + Prompt: message, + }) + } +} + // takes us from the patch building panel back to the commit files panel func (self *PatchBuildingHelper) Escape() { self.c.Context().Pop() diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 4818729b3..f0566b83d 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -292,6 +292,7 @@ type TranslationSet struct { SelectHunk string SelectLineByLine string ToggleSelectHunkTooltip string + HunkStagingHint string ToggleSelectionForPatch string EditHunk string EditHunkTooltip string @@ -1059,6 +1060,15 @@ const englishNonReloadableConfigWarning = `The following config settings were ch {{configs}}` +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. + +If you prefer to use line-by-line mode by default (like in earlier lazygit versions), add + +gui: + useHunkModeInStagingView: false + +to your lazygit config.` + // exporting this so we can use it in tests func EnglishTranslationSet() *TranslationSet { return &TranslationSet{ @@ -1342,6 +1352,7 @@ func EnglishTranslationSet() *TranslationSet { SelectHunk: "Select hunks", SelectLineByLine: "Select line-by-line", ToggleSelectHunkTooltip: "Toggle line-by-line vs. hunk selection mode.", + HunkStagingHint: englishHunkStagingHint, ToggleSelectionForPatch: `Toggle lines in patch`, EditHunk: `Edit hunk`, EditHunkTooltip: "Edit selected hunk in external editor.",