Skip to content
2 changes: 1 addition & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ gui:
wrapLinesInStagingView: true

# If true, hunk selection mode will be enabled by default when entering the staging view.
useHunkModeInStagingView: false
useHunkModeInStagingView: true

# One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
language: auto
Expand Down
4 changes: 2 additions & 2 deletions docs/keybindings/Keybindings_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` <left> `` | Go to previous hunk | |
| `` <right> `` | Go to next hunk | |
| `` v `` | Toggle range select | |
| `` a `` | Select hunk | Toggle hunk selection mode. |
| `` a `` | Toggle hunk selection | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | Copy selected text to clipboard | |
| `` o `` | Open file | Open file in default application. |
| `` e `` | Edit file | Open file in external editor. |
Expand All @@ -236,7 +236,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` <left> `` | Go to previous hunk | |
| `` <right> `` | Go to next hunk | |
| `` v `` | Toggle range select | |
| `` a `` | Select hunk | Toggle hunk selection mode. |
| `` a `` | Toggle hunk selection | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | Copy selected text to clipboard | |
| `` <space> `` | Stage | Toggle selection staged / unstaged. |
| `` d `` | Discard | When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change. |
Expand Down
4 changes: 2 additions & 2 deletions docs/keybindings/Keybindings_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` <left> `` | 이전 hunk를 선택 | |
| `` <right> `` | 다음 hunk를 선택 | |
| `` v `` | 드래그 선택 전환 | |
| `` a `` | Toggle select hunk | Toggle hunk selection mode. |
| `` a `` | Toggle select hunk | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | 선택한 텍스트를 클립보드에 복사 | |
| `` o `` | 파일 닫기 | Open file in default application. |
| `` e `` | 파일 편집 | Open file in external editor. |
Expand All @@ -179,7 +179,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` <left> `` | 이전 hunk를 선택 | |
| `` <right> `` | 다음 hunk를 선택 | |
| `` v `` | 드래그 선택 전환 | |
| `` a `` | Toggle select hunk | Toggle hunk selection mode. |
| `` a `` | Toggle select hunk | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | 선택한 텍스트를 클립보드에 복사 | |
| `` <space> `` | Staged 전환 | 선택한 행을 staged / unstaged |
| `` d `` | 변경을 삭제 (git reset) | When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change. |
Expand Down
4 changes: 2 additions & 2 deletions docs/keybindings/Keybindings_nl.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` <left> `` | Selecteer de vorige hunk | |
| `` <right> `` | Selecteer de volgende hunk | |
| `` v `` | Toggle drag selecteer | |
| `` a `` | Toggle selecteer hunk | Toggle hunk selection mode. |
| `` a `` | Toggle selecteer hunk | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | Copy selected text to clipboard | |
| `` o `` | Open bestand | Open file in default application. |
| `` e `` | Verander bestand | Open file in external editor. |
Expand Down Expand Up @@ -302,7 +302,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
| `` <left> `` | Selecteer de vorige hunk | |
| `` <right> `` | Selecteer de volgende hunk | |
| `` v `` | Toggle drag selecteer | |
| `` a `` | Toggle selecteer hunk | Toggle hunk selection mode. |
| `` a `` | Toggle selecteer hunk | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | Copy selected text to clipboard | |
| `` <space> `` | Toggle staged | Toggle lijnen staged / unstaged |
| `` d `` | Verwijdert change (git reset) | When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change. |
Expand Down
4 changes: 2 additions & 2 deletions docs/keybindings/Keybindings_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ _Связки клавиш_
| `` <left> `` | Выбрать предыдущую часть | |
| `` <right> `` | Выбрать следующую часть | |
| `` v `` | Переключить выборку перетаскивания | |
| `` a `` | Переключить выборку частей | Toggle hunk selection mode. |
| `` a `` | Переключить выборку частей | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | Скопировать выделенный текст в буфер обмена | |
| `` <space> `` | Переключить индекс | Переключить строку в проиндексированные / непроиндексированные |
| `` d `` | Отменить изменение (git reset) | When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change. |
Expand Down Expand Up @@ -124,7 +124,7 @@ _Связки клавиш_
| `` <left> `` | Выбрать предыдущую часть | |
| `` <right> `` | Выбрать следующую часть | |
| `` v `` | Переключить выборку перетаскивания | |
| `` a `` | Переключить выборку частей | Toggle hunk selection mode. |
| `` a `` | Переключить выборку частей | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | Скопировать выделенный текст в буфер обмена | |
| `` o `` | Открыть файл | Open file in default application. |
| `` e `` | Редактировать файл | Open file in external editor. |
Expand Down
4 changes: 2 additions & 2 deletions docs/keybindings/Keybindings_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
| `` <left> `` | 選擇上一段 | |
| `` <right> `` | 選擇下一段 | |
| `` v `` | 切換拖曳選擇 | |
| `` a `` | 切換選擇程式碼塊 | Toggle hunk selection mode. |
| `` a `` | 切換選擇程式碼塊 | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | 複製所選文本至剪貼簿 | |
| `` o `` | 開啟檔案 | 使用預設軟體開啟 |
| `` e `` | 編輯檔案 | 使用外部編輯器開啟 |
Expand Down Expand Up @@ -99,7 +99,7 @@ _說明:`<c-b>` 表示 Ctrl+B、`<a-b>` 表示 Alt+B,`B`表示 Shift+B
| `` <left> `` | 選擇上一段 | |
| `` <right> `` | 選擇下一段 | |
| `` v `` | 切換拖曳選擇 | |
| `` a `` | 切換選擇程式碼塊 | Toggle hunk selection mode. |
| `` a `` | 切換選擇程式碼塊 | Toggle line-by-line vs. hunk selection mode. |
| `` <c-o> `` | 複製所選文本至剪貼簿 | |
| `` <space> `` | 切換預存 | 切換現有行的狀態 (已預存/未預存) |
| `` d `` | 刪除變更 (git reset) | When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change. |
Expand Down
3 changes: 3 additions & 0 deletions pkg/app/entry_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 6 additions & 10 deletions pkg/config/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -669,12 +670,7 @@ type AppState struct {
}

func getDefaultAppState() *AppState {
return &AppState{
LastUpdateCheck: 0,
RecentRepos: []string{},
StartupPopupVersion: 0,
LastVersion: "",
}
return &AppState{}
}

func LogPath() (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func GetDefaultConfig() *UserConfig {
MainPanelSplitMode: "flexible",
EnlargedSideViewLocation: "left",
WrapLinesInStagingView: true,
UseHunkModeInStagingView: false,
UseHunkModeInStagingView: true,
Language: "auto",
TimeFormat: "02 Jan 06",
ShortTimeFormat: time.Kitchen,
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/controllers/commits_files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
})
Expand Down
2 changes: 2 additions & 0 deletions pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/gui/controllers/helpers/patch_building_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions pkg/gui/controllers/options_menu_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (self *OptionsMenuAction) Call() error {
}
return &types.MenuItem{
OpensMenu: binding.OpensMenu,
Label: binding.Description,
Label: binding.GetDescription(),
OnPress: func() error {
if binding.Handler == nil {
return nil
Expand Down Expand Up @@ -60,7 +60,7 @@ func (self *OptionsMenuAction) getBindings(context types.Context) ([]*types.Bind
bindings, _ := self.c.GetInitialKeybindingsWithCustomCommands()

for _, binding := range bindings {
if binding.Description != "" {
if binding.GetDescription() != "" {
if binding.ViewName == "" || binding.Tag == "global" {
bindingsGlobal = append(bindingsGlobal, binding)
} else if binding.ViewName == context.GetViewName() {
Expand All @@ -80,6 +80,6 @@ func (self *OptionsMenuAction) getBindings(context types.Context) ([]*types.Bind
// handler in the keybinding struct.
func uniqueBindings(bindings []*types.Binding) []*types.Binding {
return lo.UniqBy(bindings, func(binding *types.Binding) string {
return binding.Description
return binding.GetDescription()
})
}
12 changes: 9 additions & 3 deletions pkg/gui/controllers/patch_explorer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ func (self *PatchExplorerController) GetKeybindings(opts types.KeybindingsOpts)
Description: self.c.Tr.ToggleRangeSelect,
},
{
Key: opts.GetKey(opts.Config.Main.ToggleSelectHunk),
Handler: self.withRenderAndFocus(self.HandleToggleSelectHunk),
Description: self.c.Tr.ToggleSelectHunk,
Key: opts.GetKey(opts.Config.Main.ToggleSelectHunk),
Handler: self.withRenderAndFocus(self.HandleToggleSelectHunk),
Description: self.c.Tr.ToggleSelectHunk,
DescriptionFunc: func() string {
if state := self.context.GetState(); state != nil && state.SelectingHunk() {
return self.c.Tr.SelectLineByLine
}
return self.c.Tr.SelectHunk
},
Tooltip: self.c.Tr.ToggleSelectHunkTooltip,
DisplayOnScreen: true,
},
Expand Down
7 changes: 1 addition & 6 deletions pkg/gui/options_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,9 @@ func (self *OptionsMapMgr) renderContextOptionsMap() {
displayStyle = *binding.DisplayStyle
}

description := binding.Description
if binding.ShortDescription != "" {
description = binding.ShortDescription
}

return bindingInfo{
key: keybindings.LabelFromKey(binding.Key),
description: description,
description: binding.GetShortDescription(),
style: displayStyle,
}
})
Expand Down
35 changes: 30 additions & 5 deletions pkg/gui/types/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ type Binding struct {
Key Key
Modifier gocui.Modifier
Description string
// DescriptionFunc is used instead of Description if non-nil, and is useful for dynamic
// descriptions that change depending on context. Important: this must not be an expensive call.
// Note that you should still provide a generic, non-dynamic description in the Description field,
// as this is used in the cheatsheet.
DescriptionFunc func() string
// If defined, this is used in place of Description when showing the keybinding
// in the options view at the bottom left of the screen.
ShortDescription string
Alternative string
Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
OpensMenu bool
// ShortDescriptionFunc is used instead of ShortDescription if non-nil, and is useful for dynamic
// descriptions that change depending on context. Important: this must not be an expensive call.
ShortDescriptionFunc func() string
Alternative string
Tag string // e.g. 'navigation'. Used for grouping things in the cheatsheet
OpensMenu bool

// If true, the keybinding will appear at the bottom of the screen.
// Even if set to true, the keybinding will not be displayed if it is currently
Expand All @@ -43,8 +51,25 @@ type Binding struct {
GetDisabledReason func() *DisabledReason
}

func (Binding *Binding) IsDisabled() bool {
return Binding.GetDisabledReason != nil && Binding.GetDisabledReason() != nil
func (b *Binding) IsDisabled() bool {
return b.GetDisabledReason != nil && b.GetDisabledReason() != nil
}

func (b *Binding) GetDescription() string {
if b.DescriptionFunc != nil {
return b.DescriptionFunc()
}
return b.Description
}

func (b *Binding) GetShortDescription() string {
if b.ShortDescriptionFunc != nil {
return b.ShortDescriptionFunc()
}
if b.ShortDescription != "" {
return b.ShortDescription
}
return b.GetDescription()
}

// A guard is a decorator which checks something before executing a handler
Expand Down
29 changes: 25 additions & 4 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ type TranslationSet struct {
DiscardSelection string
DiscardSelectionTooltip string
ToggleSelectHunk string
SelectHunk string
SelectLineByLine string
ToggleSelectHunkTooltip string
HunkStagingHint string
ToggleSelectionForPatch string
EditHunk string
EditHunkTooltip string
Expand Down Expand Up @@ -1057,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{
Expand Down Expand Up @@ -1336,8 +1348,11 @@ func EnglishTranslationSet() *TranslationSet {
DiscardSelection: `Discard`,
DiscardSelectionTooltip: "When unstaged change is selected, discard the change using `git reset`. When staged change is selected, unstage the change.",
ToggleRangeSelect: "Toggle range select",
ToggleSelectHunk: "Select hunk",
ToggleSelectHunkTooltip: "Toggle hunk selection mode.",
ToggleSelectHunk: "Toggle hunk selection",
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.",
Expand Down Expand Up @@ -2104,7 +2119,7 @@ keybinding:

gui:
filterMode: 'fuzzy'
`,
`,
"0.44.0": `- The gui.branchColors config option is deprecated; it will be removed in a future version. Please use gui.branchColorPatterns instead.
- The automatic coloring of branches starting with "feature/", "bugfix/", or "hotfix/" has been removed; if you want this, it's easy to set up using the new gui.branchColorPatterns option.`,
"0.49.0": `- Executing shell commands (with the ':' prompt) no longer uses an interactive shell, which means that if you want to use your shell aliases in this prompt, you need to do a little bit of setup work. See https://github.com/jesseduffield/lazygit/blob/master/docs/Config.md#using-aliases-or-functions-in-shell-commands for details.`,
Expand All @@ -2119,7 +2134,13 @@ If, on the other hand, you want this even for feature branches, you can set it t

git:
localBranchSortOrder: recency
remoteBranchSortOrder: alphabetical`,
remoteBranchSortOrder: alphabetical

- The default selection mode in the staging and custom patch building views has been changed to hunk mode. This is the more useful mode in most cases, as it usually saves a lot of keystrokes. If you want to switch back to the old line mode default, you can do so by adding the following to your config:

gui:
useHunkSelectionMode: false
`,
},
}
}
4 changes: 3 additions & 1 deletion pkg/integration/tests/commit/stage_range_of_lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ var StageRangeOfLines = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Staging a range of lines",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupConfig: func(config *config.AppConfig) {
config.GetUserConfig().Gui.UseHunkModeInStagingView = false
},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("myfile", "1st\n2nd\n3rd\n4th\n5th\n6th\n")
shell.Commit("Add file")
Expand Down
1 change: 1 addition & 0 deletions pkg/integration/tests/demo/custom_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var CustomPatch = NewIntegrationTest(NewIntegrationTestArgs{
IsDemo: true,
SetupConfig: func(cfg *config.AppConfig) {
setDefaultDemoConfig(cfg)
cfg.GetUserConfig().Gui.UseHunkModeInStagingView = false
},
SetupRepo: func(shell *Shell) {
shell.CreateNCommitsWithRandomMessages(30)
Expand Down
Loading