summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pkg/gui/arrangement.go3
-rw-r--r--pkg/gui/branches_panel.go13
-rw-r--r--pkg/gui/cherry_picking.go15
-rw-r--r--pkg/gui/commit_files_panel.go3
-rw-r--r--pkg/gui/commits_panel.go5
-rw-r--r--pkg/gui/confirmation_panel.go22
-rw-r--r--pkg/gui/context.go7
-rw-r--r--pkg/gui/context/context.go52
-rw-r--r--pkg/gui/context_config.go72
-rw-r--r--pkg/gui/custom_commands.go11
-rw-r--r--pkg/gui/diff_context_size.go19
-rw-r--r--pkg/gui/diff_context_size_test.go4
-rw-r--r--pkg/gui/diffing.go9
-rw-r--r--pkg/gui/extras_panel.go3
-rw-r--r--pkg/gui/files_panel.go5
-rw-r--r--pkg/gui/keybindings.go223
-rw-r--r--pkg/gui/list_context_config.go26
-rw-r--r--pkg/gui/merge_panel.go3
-rw-r--r--pkg/gui/patch_options_panel.go5
19 files changed, 257 insertions, 243 deletions
diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go
index 944391d75..9766d7885 100644
--- a/pkg/gui/arrangement.go
+++ b/pkg/gui/arrangement.go
@@ -2,6 +2,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/boxlayout"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -139,7 +140,7 @@ func (gui *Gui) getExtrasWindowSize(screenHeight int) int {
}
var baseSize int
- if gui.currentStaticContext().GetKey() == COMMAND_LOG_CONTEXT_KEY {
+ if gui.currentStaticContext().GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
baseSize = 1000 // my way of saying 'fill the available space'
} else if screenHeight < 40 {
baseSize = 1
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go
index 7b179e2ff..1efde5c28 100644
--- a/pkg/gui/branches_panel.go
+++ b/pkg/gui/branches_panel.go
@@ -7,6 +7,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -409,9 +410,9 @@ func (gui *Gui) handleRenameBranch() error {
}
func (gui *Gui) handleNewBranchOffCurrentItem() error {
- context := gui.currentSideListContext()
+ ctx := gui.currentSideListContext()
- item, ok := context.GetSelectedItem()
+ item, ok := ctx.GetSelectedItem()
if !ok {
return nil
}
@@ -424,7 +425,7 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
)
prefilledName := ""
- if context.GetKey() == REMOTE_BRANCHES_CONTEXT_KEY {
+ if ctx.GetKey() == context.REMOTE_BRANCHES_CONTEXT_KEY {
// will set to the remote's branch name without the remote name
prefilledName = strings.SplitAfterN(item.ID(), "/", 2)[1]
}
@@ -440,11 +441,11 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
// if we're currently in the branch commits context then the selected commit
// is about to go to the top of the list
- if context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
- context.GetPanelState().SetSelectedLineIdx(0)
+ if ctx.GetKey() == context.BRANCH_COMMITS_CONTEXT_KEY {
+ ctx.GetPanelState().SetSelectedLineIdx(0)
}
- if context.GetKey() != gui.State.Contexts.Branches.GetKey() {
+ if ctx.GetKey() != gui.State.Contexts.Branches.GetKey() {
if err := gui.c.PushContext(gui.State.Contexts.Branches); err != nil {
return err
}
diff --git a/pkg/gui/cherry_picking.go b/pkg/gui/cherry_picking.go
index be6fe379d..3cc7fca6d 100644
--- a/pkg/gui/cherry_picking.go
+++ b/pkg/gui/cherry_picking.go
@@ -2,6 +2,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -62,21 +63,21 @@ func (gui *Gui) cherryPickedCommitShaMap() map[string]bool {
}
func (gui *Gui) commitsListForContext() []*models.Commit {
- context := gui.currentSideListContext()
- if context == nil {
+ ctx := gui.currentSideListContext()
+ if ctx == nil {
return nil
}
// using a switch statement, but we should use polymorphism
- switch context.GetKey() {
- case BRANCH_COMMITS_CONTEXT_KEY:
+ switch ctx.GetKey() {
+ case context.BRANCH_COMMITS_CONTEXT_KEY:
return gui.State.Commits
- case REFLOG_COMMITS_CONTEXT_KEY:
+ case context.REFLOG_COMMITS_CONTEXT_KEY:
return gui.State.FilteredReflogCommits
- case SUB_COMMITS_CONTEXT_KEY:
+ case context.SUB_COMMITS_CONTEXT_KEY:
return gui.State.SubCommits
default:
- gui.c.Log.Errorf("no commit list for context %s", context.GetKey())
+ gui.c.Log.Errorf("no commit list for context %s", ctx.GetKey())
return nil
}
}
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index ef2c94bef..aefea5647 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -3,6 +3,7 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/patch"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -100,7 +101,7 @@ func (gui *Gui) handleDiscardOldFileChange() error {
func (gui *Gui) refreshCommitFilesView() error {
currentSideContext := gui.currentSideContext()
- if currentSideContext.GetKey() == COMMIT_FILES_CONTEXT_KEY || currentSideContext.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
+ if currentSideContext.GetKey() == context.COMMIT_FILES_CONTEXT_KEY || currentSideContext.GetKey() == context.BRANCH_COMMITS_CONTEXT_KEY {
if err := gui.handleRefreshPatchBuildingPanel(-1); err != nil {
return err
}
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 6f80ee5c3..26b3fac09 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -5,6 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/utils"
)
@@ -91,8 +92,8 @@ func (gui *Gui) refreshCommits() {
go utils.Safe(func() {
_ = gui.refreshCommitsWithLimit()
- context, ok := gui.State.Contexts.CommitFiles.GetParentContext()
- if ok && context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
+ ctx, ok := gui.State.Contexts.CommitFiles.GetParentContext()
+ if ok && ctx.GetKey() == context.BRANCH_COMMITS_CONTEXT_KEY {
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position.
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
// showing the contents of a different commit than the one we initially entered.
diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go
index 51c71b30b..d136b7d7f 100644
--- a/pkg/gui/confirmation_panel.go
+++ b/pkg/gui/confirmation_panel.go
@@ -5,7 +5,7 @@ import (
"strings"
"github.com/jesseduffield/gocui"
- "github.com/jesseduffield/lazygit/pkg/gui/popup"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -138,7 +138,7 @@ func (gui *Gui) prepareConfirmationPanel(
return nil
}
-func (gui *Gui) createPopupPanel(opts popup.CreatePopupPanelOpts) error {
+func (gui *Gui) createPopupPanel(opts types.CreatePopupPanelOpts) error {
// remove any previous keybindings
gui.clearConfirmationViewKeyBindings()
@@ -174,7 +174,7 @@ func (gui *Gui) createPopupPanel(opts popup.CreatePopupPanelOpts) error {
return gui.c.PushContext(gui.State.Contexts.Confirmation)
}
-func (gui *Gui) setKeyBindings(opts popup.CreatePopupPanelOpts) error {
+func (gui *Gui) setKeyBindings(opts types.CreatePopupPanelOpts) error {
actions := utils.ResolvePlaceholderString(
gui.c.Tr.CloseConfirm,
map[string]string{
@@ -201,25 +201,25 @@ func (gui *Gui) setKeyBindings(opts popup.CreatePopupPanelOpts) error {
bindings := []*types.Binding{
{
ViewName: "confirmation",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Confirm),
Handler: onConfirm,
},
{
ViewName: "confirmation",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
Handler: onConfirm,
},
{
ViewName: "confirmation",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Return),
Handler: gui.wrappedConfirmationFunction(opts.HandlersManageFocus, opts.HandleClose),
},
{
ViewName: "confirmation",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
Handler: func() error {
if len(gui.State.Suggestions) > 0 {
@@ -230,25 +230,25 @@ func (gui *Gui) setKeyBindings(opts popup.CreatePopupPanelOpts) error {
},
{
ViewName: "suggestions",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Confirm),
Handler: onSuggestionConfirm,
},
{
ViewName: "suggestions",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.ConfirmAlt1),
Handler: onSuggestionConfirm,
},
{
ViewName: "suggestions",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.Return),
Handler: gui.wrappedConfirmationFunction(opts.HandlersManageFocus, opts.HandleClose),
},
{
ViewName: "suggestions",
- Contexts: []string{string(CONFIRMATION_CONTEXT_KEY)},
+ Contexts: []string{string(context.CONFIRMATION_CONTEXT_KEY)},
Key: gui.getKey(keybindingConfig.Universal.TogglePanel),
Handler: func() error { return gui.replaceContext(gui.State.Contexts.Confirmation) },
},
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index f92c73e26..1c115c04b 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/jesseduffield/gocui"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -130,7 +131,7 @@ func (gui *Gui) deactivateContext(c types.Context) error {
}
// if we are the kind of context that is sent to back upon deactivation, we should do that
- if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || c.GetKey() == COMMIT_FILES_CONTEXT_KEY) {
+ if view != nil && (c.GetKind() == types.TEMPORARY_POPUP || c.GetKind() == types.PERSISTENT_POPUP || c.GetKey() == context.COMMIT_FILES_CONTEXT_KEY) {
view.Visible = false
}
@@ -181,7 +182,7 @@ func (gui *Gui) activateContext(c types.Context, opts ...types.OnFocusOpts) erro
if viewName == "main" {
gui.changeMainViewsContext(c.GetKey())
} else {
- gui.changeMainViewsContext(MAIN_NORMAL_CONTEXT_KEY)
+ gui.changeMainViewsContext(context.MAIN_NORMAL_CONTEXT_KEY)
}
gui.setViewTabForContext(c)
@@ -382,7 +383,7 @@ func (gui *Gui) changeMainViewsContext(contextKey types.ContextKey) {
}
switch contextKey {
- case MAIN_NORMAL_CONTEXT_KEY, MAIN_PATCH_BUILDING_CONTEXT_KEY, MAIN_STAGING_CONTEXT_KEY, MAIN_MERGING_CONTEXT_KEY:
+ case context.MAIN_NORMAL_CONTEXT_KEY, context.MAIN_PATCH_BUILDING_CONTEXT_KEY, context.MAIN_STAGING_CONTEXT_KEY, context.MAIN_MERGING_CONTEXT_KEY:
gui.Views.Main.Context = string(contextKey)
gui.Views.Secondary.Context = string(contextKey)
default:
diff --git a/pkg/gui/context/context.go b/pkg/gui/context/context.go
index 30030990f..13d63b9e9 100644
--- a/pkg/gui/context/context.go
+++ b/pkg/gui/context/context.go
@@ -2,6 +2,58 @@ package context
import "github.com/jesseduffield/lazygit/pkg/gui/types"
+const (
+ STATUS_CONTEXT_KEY types.ContextKey = "status"
+ FILES_CONTEXT_KEY types.ContextKey = "files"
+ LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
+ REMOTES_CONTEXT_KEY types.ContextKey = "remotes"
+ REMOTE_BRANCHES_CONTEXT_KEY types.ContextKey = "remoteBranches"
+ TAGS_CONTEXT_KEY types.ContextKey = "tags"
+ BRANCH_COMMITS_CONTEXT_KEY types.ContextKey = "commits"
+ REFLOG_COMMITS_CONTEXT_KEY types.ContextKey = "reflogCommits"
+ SUB_COMMITS_CONTEXT_KEY types.ContextKey = "subCommits"
+ COMMIT_FILES_CONTEXT_KEY types.ContextKey = "commitFiles"
+ STASH_CONTEXT_KEY types.ContextKey = "stash"
+ MAIN_NORMAL_CONTEXT_KEY types.ContextKey = "normal"
+ MAIN_MERGING_CONTEXT_KEY types.ContextKey = "merging"
+ MAIN_PATCH_BUILDING_CONTEXT_KEY types.ContextKey = "patchBuilding"
+ MAIN_STAGING_CONTEXT_KEY types.ContextKey = "staging"
+ MENU_CONTEXT_KEY types.ContextKey = "menu"
+ CREDENTIALS_CONTEXT_KEY types.ContextKey = "credentials"
+ CONFIRMATION_CONTEXT_KEY types.ContextKey = "confirmation"
+ SEARCH_CONTEXT_KEY types.ContextKey = "search"
+ COMMIT_MESSAGE_CONTEXT_KEY types.ContextKey = "commitMessage"
+ SUBMODULES_CONTEXT_KEY types.ContextKey = "submodules"
+ SUGGESTIONS_CONTEXT_KEY types.ContextKey = "suggestions"
+ COMMAND_LOG_CONTEXT_KEY types.ContextKey = "cmdLog"
+)
+
+var AllContextKeys = []types.ContextKey{
+ STATUS_CONTEXT_KEY,
+ FILES_CONTEXT_KEY,
+ LOCAL_BRANCHES_CONTEXT_KEY,
+ REMOTES_CONTEXT_KEY,
+ REMOTE_BRANCHES_CONTEXT_KEY,
+ TAGS_CONTEXT_KEY,
+ BRANCH_COMMITS_CONTEXT_KEY,
+ REFLOG_COMMITS_CONTEXT_KEY,
+ SUB_COMMITS_CONTEXT_KEY,
+ COMMIT_FILES_CONTEXT_KEY,
+ STASH_CONTEXT_KEY,
+ MAIN_NORMAL_CONTEXT_KEY,
+ MAIN_MERGING_CONTEXT_KEY,
+ MAIN_PATCH_BUILDING_CONTEXT_KEY,
+ MAIN_STAGING_CONTEXT_KEY,
+ MENU_CONTEXT_KEY,
+ CREDENTIALS_CONTEXT_KEY,
+ CONFIRMATION_CONTEXT_KEY,
+ SEARCH_CONTEXT_KEY,
+ COMMIT_MESSAGE_CONTEXT_KEY,
+ SUBMODULES_CONTEXT_KEY,
+ SUGGESTIONS_CONTEXT_KEY,
+ COMMAND_LOG_CONTEXT_KEY,
+}
+
type ContextTree struct {
Status types.Context
Files types.IListContext
diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go
index d2903f705..c5c2bf544 100644
--- a/pkg/gui/context_config.go
+++ b/pkg/gui/context_config.go
@@ -5,58 +5,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
-const (
- STATUS_CONTEXT_KEY types.ContextKey = "status"
- FILES_CONTEXT_KEY types.ContextKey = "files"
- LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
- REMOTES_CONTEXT_KEY types.ContextKey = "remotes"
- REMOTE_BRANCHES_CONTEXT_KEY types.ContextKey = "remoteBranches"
- TAGS_CONTEXT_KEY types.ContextKey = "tags"
- BRANCH_COMMITS_CONTEXT_KEY types.ContextKey = "commits"
- REFLOG_COMMITS_CONTEXT_KEY types.ContextKey = "reflogCommits"
- SUB_COMMITS_CONTEXT_KEY types.ContextKey = "subCommits"
- COMMIT_FILES_CONTEXT_KEY types.ContextKey = "commitFiles"
- STASH_CONTEXT_KEY types.ContextKey = "stash"
- MAIN_NORMAL_CONTEXT_KEY types.ContextKey = "normal"
- MAIN_MERGING_CONTEXT_KEY types.ContextKey = "merging"
- MAIN_PATCH_BUILDING_CONTEXT_KEY types.ContextKey = "patchBuilding"
- MAIN_STAGING_CONTEXT_KEY types.ContextKey = "staging"
- MENU_CONTEXT_KEY types.ContextKey = "menu"
- CREDENTIALS_CONTEXT_KEY types.ContextKey = "credentials"
- CONFIRMATION_CONTEXT_KEY types.ContextKey = "confirmation"
- SEARCH_CONTEXT_KEY types.ContextKey = "search"
- COMMIT_MESSAGE_CONTEXT_KEY types.ContextKey = "commitMessage"
- SUBMODULES_CONTEXT_KEY types.ContextKey = "submodules"
- SUGGESTIONS_CONTEXT_KEY types.ContextKey = "suggestions"
- COMMAND_LOG_CONTEXT_KEY types.ContextKey = "cmdLog"
-)
-
-var AllContextKeys = []types.ContextKey{
- STATUS_CONTEXT_KEY,
- FILES_CONTEXT_KEY,
- LOCAL_BRANCHES_CONTEXT_KEY,
- REMOTES_CONTEXT_KEY,
- REMOTE_BRANCHES_CONTEXT_KEY,
- TAGS_CONTEXT_KEY,
- BRANCH_COMMITS_CONTEXT_KEY,
- REFLOG_COMMITS_CONTEXT_KEY,
- SUB_COMMITS_CONTEXT_KEY,
- COMMIT_FILES_CONTEXT_KEY,
- STASH_CONTEXT_KEY,
- MAIN_NORMAL_CONTEXT_KEY,
- MAIN_MERGING_CONTEXT_KEY,
- MAIN_PATCH_BUILDING_CONTEXT_KEY,
- MAIN_STAGING_CONTEXT_KEY,
- MENU_CONTEXT_KEY,
- CREDENTIALS_CONTEXT_KEY,
- CONFIRMATION_CONTEXT_KEY,
- SEARCH_CONTEXT_KEY,
- COMMIT_MESSAGE_CONTEXT_KEY,
- SUBMODULES_CONTEXT_KEY,
- SUGGESTIONS_CONTEXT_KEY,
- COMMAND_LOG_CONTEXT_KEY,
-}
-
func (gui *Gui) allContexts() []types.Context {
return []types.Context{
gui.State.Contexts.Status,
@@ -90,7 +38,7 @@ func (gui *Gui) contextTree() context.ContextTree {
context.NewBaseContext(context.NewBaseContextOpts{
Kind: types.SIDE_CONTEXT,
ViewName: "status",
- Key: STATUS_CONTEXT_KEY,
+ Key: context.STATUS_CONTEXT_KEY,
WindowName: "status",
}),
NewSimpleContextOpts{
@@ -115,7 +63,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
- Key: MAIN_NORMAL_CONTEXT_KEY,
+ Key: context.MAIN_NORMAL_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: func(opts ...types.OnFocusOpts) error {
@@ -128,7 +76,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
- Key: MAIN_STAGING_CONTEXT_KEY,
+ Key: context.MAIN_STAGING_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: func(opts ...types.OnFocusOpts) error {
@@ -151,7 +99,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
- Key: MAIN_PATCH_BUILDING_CONTEXT_KEY,
+ Key: context.MAIN_PATCH_BUILDING_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: func(opts ...types.OnFocusOpts) error {
@@ -169,7 +117,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.MAIN_CONTEXT,
ViewName: "main",
WindowName: "main",
- Key: MAIN_MERGING_CONTEXT_KEY,
+ Key: context.MAIN_MERGING_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
}),
NewSimpleContextOpts{
@@ -181,7 +129,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.PERSISTENT_POPUP,
ViewName: "credentials",
WindowName: "credentials",
- Key: CREDENTIALS_CONTEXT_KEY,
+ Key: context.CREDENTIALS_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: OnFocusWrapper(gui.handleAskFocused),
@@ -192,7 +140,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.TEMPORARY_POPUP,
ViewName: "confirmation",
WindowName: "confirmation",
- Key: CONFIRMATION_CONTEXT_KEY,
+ Key: context.CONFIRMATION_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: OnFocusWrapper(gui.handleAskFocused),
@@ -203,7 +151,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.PERSISTENT_POPUP,
ViewName: "commitMessage",
WindowName: "commitMessage",
- Key: COMMIT_MESSAGE_CONTEXT_KEY,
+ Key: context.COMMIT_MESSAGE_CONTEXT_KEY,
}),
NewSimpleContextOpts{
OnFocus: OnFocusWrapper(gui.handleCommitMessageFocused),
@@ -214,7 +162,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.PERSISTENT_POPUP,
ViewName: "search",
WindowName: "search",
- Key: SEARCH_CONTEXT_KEY,
+ Key: context.SEARCH_CONTEXT_KEY,
}),
NewSimpleContextOpts{},
),
@@ -223,7 +171,7 @@ func (gui *Gui) contextTree() context.ContextTree {
Kind: types.EXTRAS_CONTEXT,
ViewName: "extras",
WindowName: "extras",
- Key: COMMAND_LOG_CONTEXT_KEY,
+ Key: context.COMMAND_LOG_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
}),
NewSimpleContextOpts{
diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go
index 351ee46e9..45713968e 100644
--- a/pkg/gui/custom_commands.go
+++ b/pkg/gui/custom_commands.go
@@ -12,6 +12,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/config"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -314,11 +315,11 @@ func (gui *Gui) GetCustomCommandKeybindings() []*types.Binding {
case "":
log.Fatalf("Error parsing custom command keybindings: context not provided (use context: 'global' for the global context). Key: %s, Command: %s", customCommand.Key, customCommand.Command)
default:
- context, ok := gui.contextForContextKey(types.ContextKey(customCommand.Context))
+ ctx, ok := gui.contextForContextKey(types.ContextKey(customCommand.Context))
// stupid golang making me build an array of strings for this.
- allContextKeyStrings := make([]string, len(AllContextKeys))
- for i := range AllContextKeys {
- allContextKeyStrings[i] = string(AllContextKeys[i])
+ allContextKeyStrings := make([]string, len(context.AllContextKeys))
+ for i := range context.AllContextKeys {
+ allContextKeyStrings[i] = string(context.AllContextKeys[i])
}
if !ok {
log.Fatalf("Error when setting custom command keybindings: unknown context: %s. Key: %s, Command: %s.\nPermitted contexts: %s", customCommand.Context, customCommand.Key, customCommand.Command, strings.Join(allContextKeyStrings, ", "))
@@ -326,7 +327,7 @@ func (gui *Gui) GetCustomCommandKeybindings() []*types.Binding {
// here we assume that a given context will always belong to the same view.
// Currently this is a safe bet but it's by no means guaranteed in the long term
// and we might need to make some changes in the future to support it.
- viewName = context.GetViewName()
+ viewName = ctx.GetViewName()
contexts = []string{customCommand.Context}
}
diff --git a/pkg/gui/diff_context_size.go b/pkg/gui/diff_context_size.go
index 5caefd032..e16b26852 100644
--- a/pkg/gui/diff_context_size.go
+++ b/pkg/gui/diff_context_size.go
@@ -3,17 +3,18 @@ package gui
import (
"errors"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
var CONTEXT_KEYS_SHOWING_DIFFS = []types.ContextKey{
- FILES_CONTEXT_KEY,
- COMMIT_FILES_CONTEXT_KEY,
- STASH_CONTEXT_KEY,
- BRANCH_COMMITS_CONTEXT_KEY,
- SUB_COMMITS_CONTEXT_KEY,
- MAIN_STAGING_CONTEXT_KEY,
- MAIN_PATCH_BUILDING_CONTEXT_KEY,
+ context.FILES_CONTEXT_KEY,
+ context.COMMIT_FILES_CONTEXT_KEY,
+ context.STASH_CONTEXT_KEY,
+ context.BRANCH_COMMITS_CONTEXT_KEY,
+ context.SUB_COMMITS_CONTEXT_KEY,
+ context.MAIN_STAGING_CONTEXT_KEY,
+ context.MAIN_PATCH_BUILDING_CONTEXT_KEY,
}
func isShowingDiff(gui *Gui) bool {
@@ -59,9 +60,9 @@ func (gui *Gui) handleDiffContextSizeChange() error {
currentContext := gui.currentStaticContext()
switch currentContext.GetKey() {
// we make an exception for our staging and patch building contexts because they actually need to refresh their state afterwards.
- case MAIN_PATCH_BUILDING_CONTEXT_KEY:
+ case context.MAIN_PATCH_BUILDING_CONTEXT_KEY:
return gui.handleRefreshPatchBuildingPanel(-1)
- case MAIN_STAGING_CONTEXT_KEY:
+ case context.MAIN_STAGING_CONTEXT_KEY:
return gui.handleRefreshStagingPanel(false, -1)
default:
return currentContext.HandleRenderToMain()
diff --git a/pkg/gui/diff_context_size_test.go b/pkg/gui/diff_context_size_test.go
index 8b77840db..62a784380 100644
--- a/pkg/gui/diff_context_size_test.go
+++ b/pkg/gui/diff_context_size_test.go
@@ -6,13 +6,13 @@ package gui
// +++ b/pkg/gui/diff_context_size.go
// @@ -9,12 +9,12 @@ func getRefreshFunction(gui *Gui) func()error {
// }
-// } else if key == MAIN_STAGING_CONTEXT_KEY {
+// } else if key == context.MAIN_STAGING_CONTEXT_KEY {
// return func() error {
// - selectedLine := gui.Views.Secondary.SelectedLineIdx()
// + selectedLine := gui.State.Panels.LineByLine.GetSelectedLineIdx()
// return gui.handleRefreshStagingPanel(false, selectedLine)
// }
-// } else if key == MAIN_PATCH_BUILDING_CONTEXT_KEY {
+// } else if key == context.MAIN_PATCH_BUILDING_CONTEXT_KEY {
// `
// func setupGuiForTest(gui *Gui) {
diff --git a/pkg/gui/diffing.go b/pkg/gui/diffing.go
index 0448e3147..3977e6b45 100644
--- a/pkg/gui/diffing.go
+++ b/pkg/gui/diffing.go
@@ -4,6 +4,7 @@ import (
"fmt"
"strings"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -35,12 +36,12 @@ func (gui *Gui) currentDiffTerminals() []string {
switch gui.currentContext().GetKey() {
case "":
return nil
- case FILES_CONTEXT_KEY, SUBMODULES_CONTEXT_KEY:
+ case context.FILES_CONTEXT_KEY, context.SUBMODULES_CONTEXT_KEY:
// TODO: should we just return nil here?
return []string{""}
- case COMMIT_FILES_CONTEXT_KEY:
+ case context.COMMIT_FILES_CONTEXT_KEY:
return []string{gui.State.Panels.CommitFiles.refName}
- case LOCAL_BRANCHES_CONTEXT_KEY:
+ case context.LOCAL_BRANCHES_CONTEXT_KEY:
// for our local branches we want to include both the branch and its upstream
branch := gui.getSelectedBranch()
if branch != nil {
@@ -74,7 +75,7 @@ func (gui *Gui) currentDiffTerminal() string {
func (gui *Gui) currentlySelectedFilename() string {
switch gui.currentContext().GetKey() {
- case FILES_CONTEXT_KEY, COMMIT_FILES_CONTEXT_KEY:
+ case context.FILES_CONTEXT_KEY, context.COMMIT_FILES_CONTEXT_KEY:
return gui.getSideContextSelectedItemId()
default:
return ""
diff --git a/pkg/gui/extras_panel.go b/pkg/gui/extras_panel.go
index 8b6789128..bb0eaf934 100644
--- a/pkg/gui/extras_panel.go
+++ b/pkg/gui/extras_panel.go
@@ -3,6 +3,7 @@ package gui
import (
"io"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -15,7 +16,7 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
DisplayString: gui.c.Tr.ToggleShowCommandLog,
OnPress: func() error {
currentContext := gui.currentStaticContext()
- if gui.ShowExtrasWindow && currentContext.GetKey() == COMMAND_LOG_CONTEXT_KEY {
+ if gui.ShowExtrasWindow && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
if err := gui.returnFromContext(); err != nil {
return err
}
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go
index 4e2e062bd..04d05df6f 100644
--- a/pkg/gui/files_panel.go
+++ b/pkg/gui/files_panel.go
@@ -5,6 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
"github.com/jesseduffield/lazygit/pkg/gui/types"
@@ -113,14 +114,14 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
gui.c.Log.Error(err)
}
- if types.ContextKey(gui.Views.Files.Context) == FILES_CONTEXT_KEY {
+ if types.ContextKey(gui.Views.Files.Context) == context.FILES_CONTEXT_KEY {
// doing this a little custom (as opposed to using gui.c.PostRefreshUpdate) because we handle selecting the file explicitly below
if err := gui.State.Contexts.Files.HandleRender(); err != nil {
return err
}
}
- if gui.currentContext().GetKey() == FILES_CONTEXT_KEY {
+ if gui.currentContext().GetKey() == context.FILES_CONTEXT_KEY {
currentSelectedPath := gui.getSelectedPath()
alreadySelected := prevSelectedPath != "" && currentSelectedPath == prevSelectedPath
if !alreadySelected {
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index b9197d1b4..b47c34994 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -9,6 +9,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/constants"
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@@ -355,7 +356,7 @@ func (gui *Gui) GetInitialKeybindings() []*types.Binding {
},
{
ViewName: "files",