1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

refactor of contexts and filtering

This commit is contained in:
Jesse Duffield
2021-04-03 11:32:14 +11:00
parent 5289d49f75
commit bc9a99387f
35 changed files with 299 additions and 334 deletions

View File

@ -69,7 +69,7 @@ func (gui *Gui) refreshBranches() {
} }
gui.State.Branches = builder.Build() gui.State.Branches = builder.Build()
if err := gui.postRefreshUpdate(gui.Contexts.Branches.Context); err != nil { if err := gui.postRefreshUpdate(gui.Contexts.Branches); err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }
@ -507,8 +507,8 @@ func (gui *Gui) handleNewBranchOffCurrentItem() error {
context.GetPanelState().SetSelectedLineIdx(0) context.GetPanelState().SetSelectedLineIdx(0)
} }
if context.GetKey() != gui.Contexts.Branches.Context.GetKey() { if context.GetKey() != gui.Contexts.Branches.GetKey() {
if err := gui.pushContext(gui.Contexts.Branches.Context); err != nil { if err := gui.pushContext(gui.Contexts.Branches); err != nil {
return err return err
} }
} }

View File

@ -107,7 +107,7 @@ func (gui *Gui) refreshCommitFilesView() error {
} }
gui.State.CommitFileManager.SetFiles(files, to) gui.State.CommitFileManager.SetFiles(files, to)
return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context) return gui.postRefreshUpdate(gui.Contexts.CommitFiles)
} }
func (gui *Gui) handleOpenOldCommitFile() error { func (gui *Gui) handleOpenOldCommitFile() error {
@ -167,7 +167,7 @@ func (gui *Gui) handleToggleFileForPatch() error {
gui.GitCommand.PatchManager.Reset() gui.GitCommand.PatchManager.Reset()
} }
return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context) return gui.postRefreshUpdate(gui.Contexts.CommitFiles)
} }
if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileManager.GetParent() { if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileManager.GetParent() {
@ -215,7 +215,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
} }
} }
if err := gui.pushContext(gui.Contexts.PatchBuilding.Context); err != nil { if err := gui.pushContext(gui.Contexts.PatchBuilding); err != nil {
return err return err
} }
return gui.handleRefreshPatchBuildingPanel(selectedLineIdx) return gui.handleRefreshPatchBuildingPanel(selectedLineIdx)
@ -231,7 +231,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
return enterTheFile(selectedLineIdx) return enterTheFile(selectedLineIdx)
}, },
handleClose: func() error { handleClose: func() error {
return gui.pushContext(gui.Contexts.CommitFiles.Context) return gui.pushContext(gui.Contexts.CommitFiles)
}, },
}) })
} }
@ -247,7 +247,7 @@ func (gui *Gui) handleToggleCommitFileDirCollapsed() error {
gui.State.CommitFileManager.ToggleCollapsed(node.GetPath()) gui.State.CommitFileManager.ToggleCollapsed(node.GetPath())
if err := gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context); err != nil { if err := gui.postRefreshUpdate(gui.Contexts.CommitFiles); err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }
@ -262,14 +262,14 @@ func (gui *Gui) switchToCommitFilesContext(refName string, canRebase bool, conte
gui.State.Panels.CommitFiles.SelectedLineIdx = 0 gui.State.Panels.CommitFiles.SelectedLineIdx = 0
gui.State.Panels.CommitFiles.refName = refName gui.State.Panels.CommitFiles.refName = refName
gui.State.Panels.CommitFiles.canRebase = canRebase gui.State.Panels.CommitFiles.canRebase = canRebase
gui.Contexts.CommitFiles.Context.SetParentContext(context) gui.Contexts.CommitFiles.SetParentContext(context)
gui.Contexts.CommitFiles.Context.SetWindowName(windowName) gui.Contexts.CommitFiles.SetWindowName(windowName)
if err := gui.refreshCommitFilesView(); err != nil { if err := gui.refreshCommitFilesView(); err != nil {
return err return err
} }
return gui.pushContext(gui.Contexts.CommitFiles.Context) return gui.pushContext(gui.Contexts.CommitFiles)
} }
// NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics // NOTE: this is very similar to handleToggleFileTreeView, could be DRY'd with generics
@ -283,12 +283,12 @@ func (gui *Gui) handleToggleCommitFileTreeView() error {
gui.State.CommitFileManager.ExpandToPath(path) gui.State.CommitFileManager.ExpandToPath(path)
index, found := gui.State.CommitFileManager.GetIndexForPath(path) index, found := gui.State.CommitFileManager.GetIndexForPath(path)
if found { if found {
gui.commitFilesListContext().GetPanelState().SetSelectedLineIdx(index) gui.Contexts.CommitFiles.GetPanelState().SetSelectedLineIdx(index)
} }
} }
if gui.getCommitFilesView().Context == COMMIT_FILES_CONTEXT_KEY { if gui.getCommitFilesView().Context == COMMIT_FILES_CONTEXT_KEY {
if err := gui.Contexts.CommitFiles.Context.HandleRender(); err != nil { if err := gui.Contexts.CommitFiles.HandleRender(); err != nil {
return err return err
} }
} }

View File

@ -12,7 +12,7 @@ import (
func (gui *Gui) getSelectedLocalCommit() *models.Commit { func (gui *Gui) getSelectedLocalCommit() *models.Commit {
selectedLine := gui.State.Panels.Commits.SelectedLineIdx selectedLine := gui.State.Panels.Commits.SelectedLineIdx
if selectedLine == -1 { if selectedLine == -1 || selectedLine > len(gui.State.Commits)-1 {
return nil return nil
} }
@ -38,7 +38,7 @@ func (gui *Gui) handleCommitSelect() error {
task = gui.createRenderStringTask(gui.Tr.NoCommitsThisBranch) task = gui.createRenderStringTask(gui.Tr.NoCommitsThisBranch)
} else { } else {
cmd := gui.OSCommand.ExecutableFromString( cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path), gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()),
) )
task = gui.createRunPtyTask(cmd) task = gui.createRunPtyTask(cmd)
} }
@ -86,7 +86,7 @@ func (gui *Gui) refreshCommits() error {
go utils.Safe(func() { go utils.Safe(func() {
_ = gui.refreshCommitsWithLimit() _ = gui.refreshCommitsWithLimit()
context, ok := gui.Contexts.CommitFiles.Context.GetParentContext() context, ok := gui.Contexts.CommitFiles.GetParentContext()
if ok && context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY { if ok && context.GetKey() == 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. // 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 // However if we've just added a brand new commit, it pushes the list down by one and so we would end up
@ -117,7 +117,7 @@ func (gui *Gui) refreshCommitsWithLimit() error {
commits, err := builder.GetCommits( commits, err := builder.GetCommits(
commands.GetCommitsOptions{ commands.GetCommitsOptions{
Limit: gui.State.Panels.Commits.LimitCommits, Limit: gui.State.Panels.Commits.LimitCommits,
FilterPath: gui.State.Modes.Filtering.Path, FilterPath: gui.State.Modes.Filtering.GetPath(),
IncludeRebaseCommits: true, IncludeRebaseCommits: true,
RefName: "HEAD", RefName: "HEAD",
}, },
@ -127,7 +127,7 @@ func (gui *Gui) refreshCommitsWithLimit() error {
} }
gui.State.Commits = commits gui.State.Commits = commits
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context) return gui.postRefreshUpdate(gui.Contexts.BranchCommits)
} }
func (gui *Gui) refreshRebaseCommits() error { func (gui *Gui) refreshRebaseCommits() error {
@ -142,7 +142,7 @@ func (gui *Gui) refreshRebaseCommits() error {
} }
gui.State.Commits = updatedCommits gui.State.Commits = updatedCommits
return gui.postRefreshUpdate(gui.Contexts.BranchCommits.Context) return gui.postRefreshUpdate(gui.Contexts.BranchCommits)
} }
// specific functions // specific functions
@ -444,7 +444,7 @@ func (gui *Gui) handleViewCommitFiles() error {
return nil return nil
} }
return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits.Context, "commits") return gui.switchToCommitFilesContext(commit.Sha, true, gui.Contexts.BranchCommits, "commits")
} }
func (gui *Gui) handleCreateFixupCommit() error { func (gui *Gui) handleCreateFixupCommit() error {

View File

@ -204,7 +204,7 @@ func (gui *Gui) prepareConfirmationPanel(title, prompt string, hasLoader bool, f
} }
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
return gui.pushContext(gui.Contexts.Confirmation.Context) return gui.pushContext(gui.Contexts.Confirmation)
}) })
return confirmationView, nil return confirmationView, nil
} }
@ -284,7 +284,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error {
{ {
viewName: "confirmation", viewName: "confirmation",
key: gui.getKey(keybindingConfig.Universal.TogglePanel), key: gui.getKey(keybindingConfig.Universal.TogglePanel),
handler: func() error { return gui.replaceContext(gui.Contexts.Suggestions.Context) }, handler: func() error { return gui.replaceContext(gui.Contexts.Suggestions) },
}, },
{ {
viewName: "suggestions", viewName: "suggestions",
@ -304,7 +304,7 @@ func (gui *Gui) setKeyBindings(opts createPopupPanelOpts) error {
{ {
viewName: "suggestions", viewName: "suggestions",
key: gui.getKey(keybindingConfig.Universal.TogglePanel), key: gui.getKey(keybindingConfig.Universal.TogglePanel),
handler: func() error { return gui.replaceContext(gui.Contexts.Confirmation.Context) }, handler: func() error { return gui.replaceContext(gui.Contexts.Confirmation) },
}, },
} }

View File

@ -65,62 +65,54 @@ var allContextKeys = []string{
SUGGESTIONS_CONTEXT_KEY, SUGGESTIONS_CONTEXT_KEY,
} }
type SimpleContextNode struct {
Context Context
}
type RemotesContextNode struct {
Context Context
Branches SimpleContextNode
}
type ContextTree struct { type ContextTree struct {
Status SimpleContextNode Status Context
Files SimpleContextNode Files *ListContext
Submodules SimpleContextNode Submodules *ListContext
Menu SimpleContextNode Menu *ListContext
Branches SimpleContextNode Branches *ListContext
Remotes RemotesContextNode Remotes *ListContext
Tags SimpleContextNode RemoteBranches *ListContext
BranchCommits SimpleContextNode Tags *ListContext
CommitFiles SimpleContextNode BranchCommits *ListContext
ReflogCommits SimpleContextNode CommitFiles *ListContext
SubCommits SimpleContextNode ReflogCommits *ListContext
Stash SimpleContextNode SubCommits *ListContext
Normal SimpleContextNode Stash *ListContext
Staging SimpleContextNode Suggestions *ListContext
PatchBuilding SimpleContextNode Normal Context
Merging SimpleContextNode Staging Context
Credentials SimpleContextNode PatchBuilding Context
Confirmation SimpleContextNode Merging Context
CommitMessage SimpleContextNode Credentials Context
Search SimpleContextNode Confirmation Context
Suggestions SimpleContextNode CommitMessage Context
Search Context
} }
func (gui *Gui) allContexts() []Context { func (gui *Gui) allContexts() []Context {
return []Context{ return []Context{
gui.Contexts.Status.Context, gui.Contexts.Status,
gui.Contexts.Files.Context, gui.Contexts.Files,
gui.Contexts.Submodules.Context, gui.Contexts.Submodules,
gui.Contexts.Branches.Context, gui.Contexts.Branches,
gui.Contexts.Remotes.Context, gui.Contexts.Remotes,
gui.Contexts.Remotes.Branches.Context, gui.Contexts.RemoteBranches,
gui.Contexts.Tags.Context, gui.Contexts.Tags,
gui.Contexts.BranchCommits.Context, gui.Contexts.BranchCommits,
gui.Contexts.CommitFiles.Context, gui.Contexts.CommitFiles,
gui.Contexts.ReflogCommits.Context, gui.Contexts.ReflogCommits,
gui.Contexts.Stash.Context, gui.Contexts.Stash,
gui.Contexts.Menu.Context, gui.Contexts.Menu,
gui.Contexts.Confirmation.Context, gui.Contexts.Confirmation,
gui.Contexts.Credentials.Context, gui.Contexts.Credentials,
gui.Contexts.CommitMessage.Context, gui.Contexts.CommitMessage,
gui.Contexts.Normal.Context, gui.Contexts.Normal,
gui.Contexts.Staging.Context, gui.Contexts.Staging,
gui.Contexts.Merging.Context, gui.Contexts.Merging,
gui.Contexts.PatchBuilding.Context, gui.Contexts.PatchBuilding,
gui.Contexts.SubCommits.Context, gui.Contexts.SubCommits,
gui.Contexts.Suggestions.Context, gui.Contexts.Suggestions,
} }
} }
@ -206,145 +198,101 @@ func (c BasicContext) GetKey() string {
func (gui *Gui) contextTree() ContextTree { func (gui *Gui) contextTree() ContextTree {
return ContextTree{ return ContextTree{
Status: SimpleContextNode{ Status: BasicContext{
Context: BasicContext{ OnFocus: gui.handleStatusSelect,
OnFocus: gui.handleStatusSelect, Kind: SIDE_CONTEXT,
Kind: SIDE_CONTEXT, ViewName: "status",
ViewName: "status", Key: STATUS_CONTEXT_KEY,
Key: STATUS_CONTEXT_KEY, },
Files: gui.filesListContext(),
Submodules: gui.submodulesListContext(),
Menu: gui.menuListContext(),
Remotes: gui.remotesListContext(),
RemoteBranches: gui.remoteBranchesListContext(),
BranchCommits: gui.branchCommitsListContext(),
CommitFiles: gui.commitFilesListContext(),
ReflogCommits: gui.reflogCommitsListContext(),
SubCommits: gui.subCommitsListContext(),
Branches: gui.branchesListContext(),
Tags: gui.tagsListContext(),
Stash: gui.stashListContext(),
Normal: BasicContext{
OnFocus: func() error {
return nil // TODO: should we do something here? We should allow for scrolling the panel
}, },
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: MAIN_NORMAL_CONTEXT_KEY,
}, },
Files: SimpleContextNode{ Staging: BasicContext{
Context: gui.filesListContext(), OnFocus: func() error {
}, return nil
Submodules: SimpleContextNode{ // TODO: centralise the code here
Context: gui.submodulesListContext(), // return gui.refreshStagingPanel(false, -1)
},
Menu: SimpleContextNode{
Context: gui.menuListContext(),
},
Remotes: RemotesContextNode{
Context: gui.remotesListContext(),
Branches: SimpleContextNode{
Context: gui.remoteBranchesListContext(),
}, },
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: MAIN_STAGING_CONTEXT_KEY,
}, },
BranchCommits: SimpleContextNode{ PatchBuilding: BasicContext{
Context: gui.branchCommitsListContext(), OnFocus: func() error {
}, return nil
CommitFiles: SimpleContextNode{ // TODO: centralise the code here
Context: gui.commitFilesListContext(), // return gui.refreshPatchBuildingPanel(-1)
},
ReflogCommits: SimpleContextNode{
Context: gui.reflogCommitsListContext(),
},
SubCommits: SimpleContextNode{
Context: gui.subCommitsListContext(),
},
Branches: SimpleContextNode{
Context: gui.branchesListContext(),
},
Tags: SimpleContextNode{
Context: gui.tagsListContext(),
},
Stash: SimpleContextNode{
Context: gui.stashListContext(),
},
Normal: SimpleContextNode{
Context: BasicContext{
OnFocus: func() error {
return nil // TODO: should we do something here? We should allow for scrolling the panel
},
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: MAIN_NORMAL_CONTEXT_KEY,
}, },
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: MAIN_PATCH_BUILDING_CONTEXT_KEY,
}, },
Staging: SimpleContextNode{ Merging: BasicContext{
Context: BasicContext{ OnFocus: gui.refreshMergePanelWithLock,
OnFocus: func() error { Kind: MAIN_CONTEXT,
return nil ViewName: "main",
// TODO: centralise the code here Key: MAIN_MERGING_CONTEXT_KEY,
// return gui.refreshStagingPanel(false, -1) OnGetOptionsMap: gui.getMergingOptions,
},
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: MAIN_STAGING_CONTEXT_KEY,
},
}, },
PatchBuilding: SimpleContextNode{ Credentials: BasicContext{
Context: BasicContext{ OnFocus: gui.handleCredentialsViewFocused,
OnFocus: func() error { Kind: PERSISTENT_POPUP,
return nil ViewName: "credentials",
// TODO: centralise the code here Key: CREDENTIALS_CONTEXT_KEY,
// return gui.refreshPatchBuildingPanel(-1)
},
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: MAIN_PATCH_BUILDING_CONTEXT_KEY,
},
}, },
Merging: SimpleContextNode{ Confirmation: BasicContext{
Context: BasicContext{ OnFocus: func() error { return nil },
OnFocus: gui.refreshMergePanelWithLock, Kind: TEMPORARY_POPUP,
Kind: MAIN_CONTEXT, ViewName: "confirmation",
ViewName: "main", Key: CONFIRMATION_CONTEXT_KEY,
Key: MAIN_MERGING_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
},
}, },
Credentials: SimpleContextNode{ Suggestions: gui.suggestionsListContext(),
Context: BasicContext{ CommitMessage: BasicContext{
OnFocus: gui.handleCredentialsViewFocused, OnFocus: gui.handleCommitMessageFocused,
Kind: PERSISTENT_POPUP, Kind: PERSISTENT_POPUP,
ViewName: "credentials", ViewName: "commitMessage",
Key: CREDENTIALS_CONTEXT_KEY, Key: COMMIT_MESSAGE_CONTEXT_KEY,
},
}, },
Confirmation: SimpleContextNode{ Search: BasicContext{
Context: BasicContext{ OnFocus: func() error { return nil },
OnFocus: func() error { return nil }, Kind: PERSISTENT_POPUP,
Kind: TEMPORARY_POPUP, ViewName: "search",
ViewName: "confirmation", Key: SEARCH_CONTEXT_KEY,
Key: CONFIRMATION_CONTEXT_KEY,
},
},
Suggestions: SimpleContextNode{
Context: gui.suggestionsListContext(),
},
CommitMessage: SimpleContextNode{
Context: BasicContext{
OnFocus: gui.handleCommitMessageFocused,
Kind: PERSISTENT_POPUP,
ViewName: "commitMessage",
Key: COMMIT_MESSAGE_CONTEXT_KEY,
},
},
Search: SimpleContextNode{
Context: BasicContext{
OnFocus: func() error { return nil },
Kind: PERSISTENT_POPUP,
ViewName: "search",
Key: SEARCH_CONTEXT_KEY,
},
}, },
} }
} }
func (gui *Gui) initialViewContextMap() map[string]Context { func (gui *Gui) initialViewContextMap() map[string]Context {
return map[string]Context{ return map[string]Context{
"status": gui.Contexts.Status.Context, "status": gui.Contexts.Status,
"files": gui.Contexts.Files.Context, "files": gui.Contexts.Files,
"branches": gui.Contexts.Branches.Context, "branches": gui.Contexts.Branches,
"commits": gui.Contexts.BranchCommits.Context, "commits": gui.Contexts.BranchCommits,
"commitFiles": gui.Contexts.CommitFiles.Context, "commitFiles": gui.Contexts.CommitFiles,
"stash": gui.Contexts.Stash.Context, "stash": gui.Contexts.Stash,
"menu": gui.Contexts.Menu.Context, "menu": gui.Contexts.Menu,
"confirmation": gui.Contexts.Confirmation.Context, "confirmation": gui.Contexts.Confirmation,
"credentials": gui.Contexts.Credentials.Context, "credentials": gui.Contexts.Credentials,
"commitMessage": gui.Contexts.CommitMessage.Context, "commitMessage": gui.Contexts.CommitMessage,
"main": gui.Contexts.Normal.Context, "main": gui.Contexts.Normal,
"secondary": gui.Contexts.Normal.Context, "secondary": gui.Contexts.Normal,
} }
} }
@ -353,41 +301,41 @@ func (gui *Gui) viewTabContextMap() map[string][]tabContext {
"branches": { "branches": {
{ {
tab: "Local Branches", tab: "Local Branches",
contexts: []Context{gui.Contexts.Branches.Context}, contexts: []Context{gui.Contexts.Branches},
}, },
{ {
tab: "Remotes", tab: "Remotes",
contexts: []Context{ contexts: []Context{
gui.Contexts.Remotes.Context, gui.Contexts.Remotes,
gui.Contexts.Remotes.Branches.Context, gui.Contexts.RemoteBranches,
}, },
}, },
{ {
tab: "Tags", tab: "Tags",
contexts: []Context{gui.Contexts.Tags.Context}, contexts: []Context{gui.Contexts.Tags},
}, },
}, },
"commits": { "commits": {
{ {
tab: "Commits", tab: "Commits",
contexts: []Context{gui.Contexts.BranchCommits.Context}, contexts: []Context{gui.Contexts.BranchCommits},
}, },
{ {
tab: "Reflog", tab: "Reflog",
contexts: []Context{ contexts: []Context{
gui.Contexts.ReflogCommits.Context, gui.Contexts.ReflogCommits,
}, },
}, },
}, },
"files": { "files": {
{ {
tab: "Files", tab: "Files",
contexts: []Context{gui.Contexts.Files.Context}, contexts: []Context{gui.Contexts.Files},
}, },
{ {
tab: "Submodules", tab: "Submodules",
contexts: []Context{ contexts: []Context{
gui.Contexts.Submodules.Context, gui.Contexts.Submodules,
}, },
}, },
}, },
@ -623,7 +571,7 @@ func (gui *Gui) currentSideContext() *ListContext {
} }
func (gui *Gui) defaultSideContext() Context { func (gui *Gui) defaultSideContext() Context {
return gui.Contexts.Files.Context return gui.Contexts.Files
} }
func (gui *Gui) setInitialViewContexts() { func (gui *Gui) setInitialViewContexts() {
@ -684,7 +632,7 @@ func (gui *Gui) onViewFocusLost(v *gocui.View, newView *gocui.View) error {
if v.Name() == "commitFiles" && newView.Name() != "main" && newView.Name() != "secondary" { if v.Name() == "commitFiles" && newView.Name() != "main" && newView.Name() != "secondary" {
gui.resetWindowForView("commitFiles") gui.resetWindowForView("commitFiles")
if err := gui.deactivateContext(gui.Contexts.CommitFiles.Context); err != nil { if err := gui.deactivateContext(gui.Contexts.CommitFiles); err != nil {
return err return err
} }
} }

View File

@ -26,7 +26,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
credentialsView.Mask = '*' credentialsView.Mask = '*'
} }
if err := gui.pushContext(gui.Contexts.Credentials.Context); err != nil { if err := gui.pushContext(gui.Contexts.Credentials); err != nil {
return err return err
} }

View File

@ -94,7 +94,7 @@ func (gui *Gui) diffStr() string {
if file != "" { if file != "" {
output += " -- " + file output += " -- " + file
} else if gui.State.Modes.Filtering.Active() { } else if gui.State.Modes.Filtering.Active() {
output += " -- " + gui.State.Modes.Filtering.Path output += " -- " + gui.State.Modes.Filtering.GetPath()
} }
return output return output

View File

@ -26,7 +26,6 @@ func (gui *Gui) GenerateSentinelErrors() {
gui.Errors = SentinelErrors{ gui.Errors = SentinelErrors{
ErrNoFiles: errors.New(gui.Tr.NoChangedFiles), ErrNoFiles: errors.New(gui.Tr.NoChangedFiles),
ErrSwitchRepo: errors.New("switching repo"), ErrSwitchRepo: errors.New("switching repo"),
ErrRestart: errors.New("restarting"),
} }
} }
@ -34,6 +33,5 @@ func (gui *Gui) sentinelErrorsArr() []error {
return []error{ return []error{
gui.Errors.ErrNoFiles, gui.Errors.ErrNoFiles,
gui.Errors.ErrSwitchRepo, gui.Errors.ErrSwitchRepo,
gui.Errors.ErrRestart,
} }
} }

View File

@ -124,13 +124,13 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
} }
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
if err := gui.postRefreshUpdate(gui.Contexts.Submodules.Context); err != nil { if err := gui.postRefreshUpdate(gui.Contexts.Submodules); err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }
if gui.getFilesView().Context == FILES_CONTEXT_KEY { if gui.getFilesView().Context == FILES_CONTEXT_KEY {
// doing this a little custom (as opposed to using gui.postRefreshUpdate) because we handle selecting the file explicitly below // doing this a little custom (as opposed to using gui.postRefreshUpdate) because we handle selecting the file explicitly below
if err := gui.Contexts.Files.Context.HandleRender(); err != nil { if err := gui.Contexts.Files.HandleRender(); err != nil {
return err return err
} }
} }
@ -210,7 +210,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
if file.HasMergeConflicts { if file.HasMergeConflicts {
return gui.createErrorPanel(gui.Tr.FileStagingRequirements) return gui.createErrorPanel(gui.Tr.FileStagingRequirements)
} }
_ = gui.pushContext(gui.Contexts.Staging.Context) _ = gui.pushContext(gui.Contexts.Staging)
return gui.handleRefreshStagingPanel(forceSecondaryFocused, selectedLineIdx) // TODO: check if this is broken, try moving into context code return gui.handleRefreshStagingPanel(forceSecondaryFocused, selectedLineIdx) // TODO: check if this is broken, try moving into context code
} }
@ -412,7 +412,7 @@ func (gui *Gui) handleCommitPress() error {
} }
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
if err := gui.pushContext(gui.Contexts.CommitMessage.Context); err != nil { if err := gui.pushContext(gui.Contexts.CommitMessage); err != nil {
return err return err
} }
@ -777,7 +777,7 @@ func (gui *Gui) handleSwitchToMerge() error {
return gui.createErrorPanel(gui.Tr.FileNoMergeCons) return gui.createErrorPanel(gui.Tr.FileNoMergeCons)
} }
return gui.pushContext(gui.Contexts.Merging.Context) return gui.pushContext(gui.Contexts.Merging)
} }
func (gui *Gui) openFile(filename string) error { func (gui *Gui) openFile(filename string) error {
@ -842,7 +842,7 @@ func (gui *Gui) handleToggleDirCollapsed() error {
gui.State.FileManager.ToggleCollapsed(node.GetPath()) gui.State.FileManager.ToggleCollapsed(node.GetPath())
if err := gui.postRefreshUpdate(gui.Contexts.Files.Context); err != nil { if err := gui.postRefreshUpdate(gui.Contexts.Files); err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }
@ -865,7 +865,7 @@ func (gui *Gui) handleToggleFileTreeView() error {
} }
if gui.getFilesView().Context == FILES_CONTEXT_KEY { if gui.getFilesView().Context == FILES_CONTEXT_KEY {
if err := gui.Contexts.Files.Context.HandleRender(); err != nil { if err := gui.Contexts.Files.HandleRender(); err != nil {
return err return err
} }
} }

View File

@ -14,6 +14,29 @@ func (gui *Gui) validateNotInFilterMode() (bool, error) {
} }
func (gui *Gui) exitFilterMode() error { func (gui *Gui) exitFilterMode() error {
gui.State.Modes.Filtering.Path = "" return gui.clearFiltering()
return gui.Errors.ErrRestart }
func (gui *Gui) clearFiltering() error {
gui.State.Modes.Filtering.Reset()
if gui.State.ScreenMode == SCREEN_HALF {
gui.State.ScreenMode = SCREEN_NORMAL
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{COMMITS}})
}
func (gui *Gui) setFiltering(path string) error {
gui.State.Modes.Filtering.SetPath(path)
if gui.State.ScreenMode == SCREEN_NORMAL {
gui.State.ScreenMode = SCREEN_HALF
}
if err := gui.pushContext(gui.Contexts.BranchCommits); err != nil {
return err
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{COMMITS}, then: func() {
gui.Contexts.BranchCommits.GetPanelState().SetSelectedLineIdx(0)
}})
} }

View File

@ -30,8 +30,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error {
menuItems = append(menuItems, &menuItem{ menuItems = append(menuItems, &menuItem{
displayString: fmt.Sprintf("%s '%s'", gui.Tr.LcFilterBy, fileName), displayString: fmt.Sprintf("%s '%s'", gui.Tr.LcFilterBy, fileName),
onPress: func() error { onPress: func() error {
gui.State.Modes.Filtering.Path = fileName return gui.setFiltering(fileName)
return gui.Errors.ErrRestart
}, },
}) })
} }
@ -42,8 +41,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error {
return gui.prompt(promptOpts{ return gui.prompt(promptOpts{
title: gui.Tr.LcEnterFileName, title: gui.Tr.LcEnterFileName,
handleConfirm: func(response string) error { handleConfirm: func(response string) error {
gui.State.Modes.Filtering.Path = strings.TrimSpace(response) return gui.setFiltering(strings.TrimSpace(response))
return gui.Errors.ErrRestart
}, },
}) })
}, },
@ -52,10 +50,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel() error {
if gui.State.Modes.Filtering.Active() { if gui.State.Modes.Filtering.Active() {
menuItems = append(menuItems, &menuItem{ menuItems = append(menuItems, &menuItem{
displayString: gui.Tr.LcExitFilterMode, displayString: gui.Tr.LcExitFilterMode,
onPress: func() error { onPress: gui.clearFiltering,
gui.State.Modes.Filtering.Path = ""
return gui.Errors.ErrRestart
},
}) })
} }

View File

@ -20,6 +20,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/tasks" "github.com/jesseduffield/lazygit/pkg/tasks"
@ -232,14 +233,6 @@ func (m *Diffing) Active() bool {
return m.Ref != "" return m.Ref != ""
} }
type Filtering struct {
Path string // the filename that gets passed to git log
}
func (m *Filtering) Active() bool {
return m.Path != ""
}
type CherryPicking struct { type CherryPicking struct {
CherryPickedCommits []*models.Commit CherryPickedCommits []*models.Commit
@ -252,7 +245,7 @@ func (m *CherryPicking) Active() bool {
} }
type Modes struct { type Modes struct {
Filtering Filtering Filtering filtering.Filtering
CherryPicking CherryPicking CherryPicking CherryPicking
Diffing Diffing Diffing Diffing
} }
@ -320,9 +313,7 @@ type guiState struct {
func (gui *Gui) resetState() { func (gui *Gui) resetState() {
// we carry over the filter path and diff state // we carry over the filter path and diff state
prevFiltering := Filtering{ prevFiltering := filtering.NewFiltering()
Path: "",
}
prevDiff := Diffing{} prevDiff := Diffing{}
prevCherryPicking := CherryPicking{ prevCherryPicking := CherryPicking{
CherryPickedCommits: make([]*models.Commit, 0), CherryPickedCommits: make([]*models.Commit, 0),
@ -380,6 +371,12 @@ func (gui *Gui) resetState() {
ViewContextMap: gui.initialViewContextMap(), ViewContextMap: gui.initialViewContextMap(),
RepoPathStack: prevRepoPathStack, RepoPathStack: prevRepoPathStack,
} }
if gui.State.Modes.Filtering.Active() {
gui.State.ScreenMode = SCREEN_HALF
} else {
gui.State.ScreenMode = SCREEN_NORMAL
}
} }
// for now the split view will always be on // for now the split view will always be on
@ -399,7 +396,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
} }
gui.resetState() gui.resetState()
gui.State.Modes.Filtering.Path = filterPath gui.State.Modes.Filtering.SetPath(filterPath)
gui.Contexts = gui.contextTree() gui.Contexts = gui.contextTree()
gui.ViewTabContextMap = gui.viewTabContextMap() gui.ViewTabContextMap = gui.viewTabContextMap()
@ -427,12 +424,6 @@ func (gui *Gui) Run() error {
go utils.Safe(gui.recordEvents) go utils.Safe(gui.recordEvents)
} }
if gui.State.Modes.Filtering.Active() {
gui.State.ScreenMode = SCREEN_HALF
} else {
gui.State.ScreenMode = SCREEN_NORMAL
}
g.OnSearchEscape = gui.onSearchEscape g.OnSearchEscape = gui.onSearchEscape
if err := gui.Config.ReloadUserConfig(); err != nil { if err := gui.Config.ReloadUserConfig(); err != nil {
return nil return nil
@ -509,7 +500,7 @@ func (gui *Gui) RunWithRestarts() error {
} }
return nil return nil
case gui.Errors.ErrSwitchRepo, gui.Errors.ErrRestart: case gui.Errors.ErrSwitchRepo:
continue continue
default: default:
return err return err

View File

@ -152,7 +152,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
branchesView.ContainsList = true branchesView.ContainsList = true
} }
commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.Context.GetWindowName(), true) commitFilesView, err := setViewFromDimensions("commitFiles", gui.Contexts.CommitFiles.GetWindowName(), true)
if err != nil { if err != nil {
if err.Error() != UNKNOWN_VIEW_ERROR_MSG { if err.Error() != UNKNOWN_VIEW_ERROR_MSG {
return err return err
@ -272,9 +272,9 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
if gui.g.CurrentView() == nil { if gui.g.CurrentView() == nil {
initialContext := gui.Contexts.Files.Context initialContext := gui.Contexts.Files
if gui.State.Modes.Filtering.Active() { if gui.State.Modes.Filtering.Active() {
initialContext = gui.Contexts.BranchCommits.Context initialContext = gui.Contexts.BranchCommits
} }
if err := gui.pushContext(initialContext); err != nil { if err := gui.pushContext(initialContext); err != nil {
@ -282,41 +282,24 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
} }
type listContextState struct { for _, listContext := range gui.getListContexts() {
view *gocui.View view, err := gui.g.View(listContext.ViewName)
listContext *ListContext if err != nil {
}
// TODO: don't we already have the view included in the context object itself? Or might that change in a way we don't want reflected here?
listContextStates := []listContextState{
{view: filesView, listContext: gui.filesListContext()},
{view: filesView, listContext: gui.submodulesListContext()},
{view: branchesView, listContext: gui.branchesListContext()},
{view: branchesView, listContext: gui.remotesListContext()},
{view: branchesView, listContext: gui.remoteBranchesListContext()},
{view: branchesView, listContext: gui.tagsListContext()},
{view: commitsView, listContext: gui.branchCommitsListContext()},
{view: commitsView, listContext: gui.reflogCommitsListContext()},
{view: stashView, listContext: gui.stashListContext()},
{view: commitFilesView, listContext: gui.commitFilesListContext()},
}
// menu view might not exist so we check to be safe
if menuView, err := gui.g.View("menu"); err == nil {
listContextStates = append(listContextStates, listContextState{view: menuView, listContext: gui.menuListContext()})
}
for _, listContextState := range listContextStates {
// ignore contexts whose view is owned by another context right now
if listContextState.view.Context != listContextState.listContext.GetKey() {
continue continue
} }
// check if the selected line is now out of view and if so refocus it
listContextState.view.FocusPoint(0, listContextState.listContext.GetPanelState().GetSelectedLineIdx())
listContextState.view.SelBgColor = theme.GocuiSelectedLineBgColor // ignore contexts whose view is owned by another context right now
if view.Context != listContext.GetKey() {
continue
}
// check if the selected line is now out of view and if so refocus it
view.FocusPoint(0, listContext.GetPanelState().GetSelectedLineIdx())
view.SelBgColor = theme.GocuiSelectedLineBgColor
// I doubt this is expensive though it's admittedly redundant after the first render // I doubt this is expensive though it's admittedly redundant after the first render
listContextState.view.SetOnSelectItem(gui.onSelectItemWrapper(listContextState.listContext.onSearchSelect)) view.SetOnSelectItem(gui.onSelectItemWrapper(listContext.onSearchSelect))
} }
gui.getMainView().SetOnSelectItem(gui.onSelectItemWrapper(gui.handlelineByLineNavigateTo)) gui.getMainView().SetOnSelectItem(gui.onSelectItemWrapper(gui.handlelineByLineNavigateTo))

View File

@ -238,7 +238,7 @@ func (gui *Gui) refreshMainViewForLineByLine(state *lBlPanelState) error {
var includedLineIndices []int var includedLineIndices []int
// I'd prefer not to have knowledge of contexts using this file but I'm not sure // I'd prefer not to have knowledge of contexts using this file but I'm not sure
// how to get around this // how to get around this
if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() { if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.GetKey() {
filename := gui.getSelectedCommitFileName() filename := gui.getSelectedCommitFileName()
var err error var err error
includedLineIndices, err = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename) includedLineIndices, err = gui.GitCommand.PatchManager.GetFileIncLineIndices(filename)
@ -341,9 +341,9 @@ func (gui *Gui) handleOpenFileAtLine() error {
// again, would be good to use inheritance here (or maybe even composition) // again, would be good to use inheritance here (or maybe even composition)
var filename string var filename string
switch gui.State.MainContext { switch gui.State.MainContext {
case gui.Contexts.PatchBuilding.Context.GetKey(): case gui.Contexts.PatchBuilding.GetKey():
filename = gui.getSelectedCommitFileName() filename = gui.getSelectedCommitFileName()
case gui.Contexts.Staging.Context.GetKey(): case gui.Contexts.Staging.GetKey():
file := gui.getSelectedFile() file := gui.getSelectedFile()
if file == nil { if file == nil {
return nil return nil

View File

@ -530,20 +530,20 @@ func (gui *Gui) suggestionsListContext() *ListContext {
func (gui *Gui) getListContexts() []*ListContext { func (gui *Gui) getListContexts() []*ListContext {
return []*ListContext{ return []*ListContext{
gui.Contexts.Menu.Context.(*ListContext), gui.Contexts.Menu,
gui.Contexts.Files.Context.(*ListContext), gui.Contexts.Files,
gui.Contexts.Branches.Context.(*ListContext), gui.Contexts.Branches,
gui.Contexts.Remotes.Context.(*ListContext), gui.Contexts.Remotes,
gui.Contexts.Remotes.Branches.Context.(*ListContext), gui.Contexts.RemoteBranches,
gui.Contexts.Tags.Context.(*ListContext), gui.Contexts.Tags,
gui.Contexts.BranchCommits.Context.(*ListContext), gui.Contexts.BranchCommits,
gui.Contexts.BranchCommits.Context.(*ListContext), gui.Contexts.BranchCommits,
gui.Contexts.ReflogCommits.Context.(*ListContext), gui.Contexts.ReflogCommits,
gui.Contexts.SubCommits.Context.(*ListContext), gui.Contexts.SubCommits,
gui.Contexts.Stash.Context.(*ListContext), gui.Contexts.Stash,
gui.Contexts.CommitFiles.Context.(*ListContext), gui.Contexts.CommitFiles,
gui.Contexts.Submodules.Context.(*ListContext), gui.Contexts.Submodules,
gui.Contexts.Suggestions.Context.(*ListContext), gui.Contexts.Suggestions,
} }
} }
@ -553,6 +553,8 @@ func (gui *Gui) getListContextKeyBindings() []*Binding {
keybindingConfig := gui.Config.GetUserConfig().Keybinding keybindingConfig := gui.Config.GetUserConfig().Keybinding
for _, listContext := range gui.getListContexts() { for _, listContext := range gui.getListContexts() {
listContext := listContext
bindings = append(bindings, []*Binding{ bindings = append(bindings, []*Binding{
{ViewName: listContext.ViewName, Tag: "navigation", Contexts: []string{listContext.ContextKey}, Key: gui.getKey(keybindingConfig.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine}, {ViewName: listContext.ViewName, Tag: "navigation", Contexts: []string{listContext.ContextKey}, Key: gui.getKey(keybindingConfig.Universal.PrevItemAlt), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
{ViewName: listContext.ViewName, Tag: "navigation", Contexts: []string{listContext.ContextKey}, Key: gui.getKey(keybindingConfig.Universal.PrevItem), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine}, {ViewName: listContext.ViewName, Tag: "navigation", Contexts: []string{listContext.ContextKey}, Key: gui.getKey(keybindingConfig.Universal.PrevItem), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},

View File

@ -88,7 +88,7 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
gui.State.Panels.Menu.SelectedLineIdx = 0 gui.State.Panels.Menu.SelectedLineIdx = 0
gui.g.Update(func(g *gocui.Gui) error { gui.g.Update(func(g *gocui.Gui) error {
return gui.pushContext(gui.Contexts.Menu.Context) return gui.pushContext(gui.Contexts.Menu)
}) })
return nil return nil
} }

View File

@ -270,7 +270,7 @@ func (gui *Gui) handleEscapeMerge() error {
// it's possible this method won't be called from the merging view so we need to // it's possible this method won't be called from the merging view so we need to
// ensure we only 'return' focus if we already have it // ensure we only 'return' focus if we already have it
if gui.g.CurrentView() == gui.getMainView() { if gui.g.CurrentView() == gui.getMainView() {
return gui.pushContext(gui.Contexts.Files.Context) return gui.pushContext(gui.Contexts.Files)
} }
return nil return nil
} }
@ -303,14 +303,14 @@ func (gui *Gui) promptToContinueRebase() error {
prompt: gui.Tr.ConflictsResolved, prompt: gui.Tr.ConflictsResolved,
handlersManageFocus: true, handlersManageFocus: true,
handleConfirm: func() error { handleConfirm: func() error {
if err := gui.pushContext(gui.Contexts.Files.Context); err != nil { if err := gui.pushContext(gui.Contexts.Files); err != nil {
return err return err
} }
return gui.genericMergeCommand("continue") return gui.genericMergeCommand("continue")
}, },
handleClose: func() error { handleClose: func() error {
return gui.pushContext(gui.Contexts.Files.Context) return gui.pushContext(gui.Contexts.Files)
}, },
}) })
} }

View File

@ -29,7 +29,7 @@ func (gui *Gui) modeStatuses() []modeStatus {
isActive: gui.State.Modes.Filtering.Active, isActive: gui.State.Modes.Filtering.Active,
description: func() string { description: func() string {
return utils.ColoredString( return utils.ColoredString(
fmt.Sprintf("%s '%s' %s", gui.Tr.LcFilteringBy, gui.State.Modes.Filtering.Path, utils.ColoredString(gui.Tr.ResetInParentheses, color.Underline)), fmt.Sprintf("%s '%s' %s", gui.Tr.LcFilteringBy, gui.State.Modes.Filtering.GetPath(), utils.ColoredString(gui.Tr.ResetInParentheses, color.Underline)),
color.FgRed, color.FgRed,
color.Bold, color.Bold,
) )

View File

@ -0,0 +1,25 @@
package filtering
type Filtering struct {
path string // the filename that gets passed to git log
}
func NewFiltering() Filtering {
return Filtering{path: ""}
}
func (m *Filtering) Active() bool {
return m.path != ""
}
func (m *Filtering) Reset() {
m.path = ""
}
func (m *Filtering) SetPath(path string) {
m.path = path
}
func (m *Filtering) GetPath() string {
return m.path
}

View File

@ -109,8 +109,8 @@ func (gui *Gui) handleEscapePatchBuildingPanel() error {
gui.GitCommand.PatchManager.Reset() gui.GitCommand.PatchManager.Reset()
} }
if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.Context.GetKey() { if gui.currentContext().GetKey() == gui.Contexts.PatchBuilding.GetKey() {
return gui.pushContext(gui.Contexts.CommitFiles.Context) return gui.pushContext(gui.Contexts.CommitFiles)
} else { } else {
// need to re-focus in case the secondary view should now be hidden // need to re-focus in case the secondary view should now be hidden
return gui.currentContext().HandleFocus() return gui.currentContext().HandleFocus()

View File

@ -42,7 +42,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error {
}, },
}...) }...)
if gui.currentContext().GetKey() == gui.Contexts.BranchCommits.Context.GetKey() { if gui.currentContext().GetKey() == gui.Contexts.BranchCommits.GetKey() {
selectedCommit := gui.getSelectedLocalCommit() selectedCommit := gui.getSelectedLocalCommit()
if selectedCommit != nil && gui.GitCommand.PatchManager.To != selectedCommit.Sha { if selectedCommit != nil && gui.GitCommand.PatchManager.To != selectedCommit.Sha {
// adding this option to index 1 // adding this option to index 1
@ -179,7 +179,7 @@ func (gui *Gui) handleApplyPatch(reverse bool) error {
func (gui *Gui) handleResetPatch() error { func (gui *Gui) handleResetPatch() error {
gui.GitCommand.PatchManager.Reset() gui.GitCommand.PatchManager.Reset()
if gui.currentContextKeyIgnoringPopups() == MAIN_PATCH_BUILDING_CONTEXT_KEY { if gui.currentContextKeyIgnoringPopups() == MAIN_PATCH_BUILDING_CONTEXT_KEY {
if err := gui.pushContext(gui.Contexts.CommitFiles.Context); err != nil { if err := gui.pushContext(gui.Contexts.CommitFiles); err != nil {
return err return err
} }
} }

View File

@ -80,7 +80,7 @@ func (gui *Gui) handleGenericMergeCommandResult(result error) error {
prompt: gui.Tr.FoundConflicts, prompt: gui.Tr.FoundConflicts,
handlersManageFocus: true, handlersManageFocus: true,
handleConfirm: func() error { handleConfirm: func() error {
return gui.pushContext(gui.Contexts.Files.Context) return gui.pushContext(gui.Contexts.Files)
}, },
handleClose: func() error { handleClose: func() error {
if err := gui.returnFromContext(); err != nil { if err := gui.returnFromContext(); err != nil {

View File

@ -73,7 +73,7 @@ func (gui *Gui) dispatchSwitchToRepo(path string) error {
return err return err
} }
gui.GitCommand = newGitCommand gui.GitCommand = newGitCommand
gui.State.Modes.Filtering.Path = "" gui.State.Modes.Filtering.Reset()
return gui.Errors.ErrSwitchRepo return gui.Errors.ErrSwitchRepo
} }

View File

@ -23,7 +23,7 @@ func (gui *Gui) handleReflogCommitSelect() error {
task = gui.createRenderStringTask("No reflog history") task = gui.createRenderStringTask("No reflog history")
} else { } else {
cmd := gui.OSCommand.ExecutableFromString( cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path), gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()),
) )
task = gui.createRunPtyTask(cmd) task = gui.createRunPtyTask(cmd)
@ -72,14 +72,14 @@ func (gui *Gui) refreshReflogCommits() error {
} }
if gui.State.Modes.Filtering.Active() { if gui.State.Modes.Filtering.Active() {
if err := refresh(&state.FilteredReflogCommits, state.Modes.Filtering.Path); err != nil { if err := refresh(&state.FilteredReflogCommits, state.Modes.Filtering.GetPath()); err != nil {
return err return err
} }
} else { } else {
state.FilteredReflogCommits = state.ReflogCommits state.FilteredReflogCommits = state.ReflogCommits
} }
return gui.postRefreshUpdate(gui.Contexts.ReflogCommits.Context) return gui.postRefreshUpdate(gui.Contexts.ReflogCommits)
} }
func (gui *Gui) handleCheckoutReflogCommit() error { func (gui *Gui) handleCheckoutReflogCommit() error {
@ -116,5 +116,5 @@ func (gui *Gui) handleViewReflogCommitFiles() error {
return nil return nil
} }
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.ReflogCommits.Context, "commits") return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.ReflogCommits, "commits")
} }

View File

@ -39,7 +39,7 @@ func (gui *Gui) handleRemoteBranchSelect() error {
} }
func (gui *Gui) handleRemoteBranchesEscape() error { func (gui *Gui) handleRemoteBranchesEscape() error {
return gui.pushContext(gui.Contexts.Remotes.Context) return gui.pushContext(gui.Contexts.Remotes)
} }
func (gui *Gui) handleMergeRemoteBranch() error { func (gui *Gui) handleMergeRemoteBranch() error {

View File

@ -80,7 +80,7 @@ func (gui *Gui) handleRemoteEnter() error {
} }
gui.State.Panels.RemoteBranches.SelectedLineIdx = newSelectedLine gui.State.Panels.RemoteBranches.SelectedLineIdx = newSelectedLine
return gui.pushContext(gui.Contexts.Remotes.Branches.Context) return gui.pushContext(gui.Contexts.RemoteBranches)
} }
func (gui *Gui) handleAddRemote() error { func (gui *Gui) handleAddRemote() error {

View File

@ -17,7 +17,7 @@ func (gui *Gui) resetToRef(ref string, strength string, options oscommands.RunCo
// loading a heap of commits is slow so we limit them whenever doing a reset // loading a heap of commits is slow so we limit them whenever doing a reset
gui.State.Panels.Commits.LimitCommits = true gui.State.Panels.Commits.LimitCommits = true
if err := gui.pushContext(gui.Contexts.BranchCommits.Context); err != nil { if err := gui.pushContext(gui.Contexts.BranchCommits); err != nil {
return err return err
} }

View File

@ -18,7 +18,7 @@ func (gui *Gui) handleOpenSearch(viewName string) error {
gui.renderString("search", "") gui.renderString("search", "")
if err := gui.pushContext(gui.Contexts.Search.Context); err != nil { if err := gui.pushContext(gui.Contexts.Search); err != nil {
return err return err
} }

View File

@ -84,7 +84,7 @@ func (gui *Gui) handleTogglePanel() error {
func (gui *Gui) handleStagingEscape() error { func (gui *Gui) handleStagingEscape() error {
gui.escapeLineByLinePanel() gui.escapeLineByLinePanel()
return gui.pushContext(gui.Contexts.Files.Context) return gui.pushContext(gui.Contexts.Files)
} }
func (gui *Gui) handleToggleStagedSelection() error { func (gui *Gui) handleToggleStagedSelection() error {
@ -107,7 +107,7 @@ func (gui *Gui) handleResetSelection() error {
handlersManageFocus: true, handlersManageFocus: true,
handleConfirm: func() error { handleConfirm: func() error {
return gui.withLBLActiveCheck(func(state *lBlPanelState) error { return gui.withLBLActiveCheck(func(state *lBlPanelState) error {
if err := gui.pushContext(gui.Contexts.Staging.Context); err != nil { if err := gui.pushContext(gui.Contexts.Staging); err != nil {
return err return err
} }
@ -115,7 +115,7 @@ func (gui *Gui) handleResetSelection() error {
}) })
}, },
handleClose: func() error { handleClose: func() error {
return gui.pushContext(gui.Contexts.Staging.Context) return gui.pushContext(gui.Contexts.Staging)
}, },
}) })
} else { } else {

View File

@ -37,9 +37,9 @@ func (gui *Gui) handleStashEntrySelect() error {
} }
func (gui *Gui) refreshStashEntries() error { func (gui *Gui) refreshStashEntries() error {
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.Modes.Filtering.Path) gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.Modes.Filtering.GetPath())
return gui.Contexts.Stash.Context.HandleRender() return gui.Contexts.Stash.HandleRender()
} }
// specific functions // specific functions
@ -134,5 +134,5 @@ func (gui *Gui) handleViewStashFiles() error {
return nil return nil
} }
return gui.switchToCommitFilesContext(stashEntry.RefName(), false, gui.Contexts.Stash.Context, "stash") return gui.switchToCommitFilesContext(stashEntry.RefName(), false, gui.Contexts.Stash, "stash")
} }

View File

@ -73,7 +73,7 @@ func (gui *Gui) handleStatusClick() error {
return nil return nil
} }
if err := gui.pushContext(gui.Contexts.Status.Context); err != nil { if err := gui.pushContext(gui.Contexts.Status); err != nil {
return err return err
} }

View File

@ -24,7 +24,7 @@ func (gui *Gui) handleSubCommitSelect() error {
task = gui.createRenderStringTask("No commits") task = gui.createRenderStringTask("No commits")
} else { } else {
cmd := gui.OSCommand.ExecutableFromString( cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.Path), gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.Modes.Filtering.GetPath()),
) )
task = gui.createRunPtyTask(cmd) task = gui.createRunPtyTask(cmd)
@ -72,7 +72,7 @@ func (gui *Gui) handleViewSubCommitFiles() error {
return nil return nil
} }
return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.SubCommits.Context, "branches") return gui.switchToCommitFilesContext(commit.Sha, false, gui.Contexts.SubCommits, "branches")
} }
func (gui *Gui) switchToSubCommitsContext(refName string) error { func (gui *Gui) switchToSubCommitsContext(refName string) error {
@ -82,7 +82,7 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error {
commits, err := builder.GetCommits( commits, err := builder.GetCommits(
commands.GetCommitsOptions{ commands.GetCommitsOptions{
Limit: gui.State.Panels.Commits.LimitCommits, Limit: gui.State.Panels.Commits.LimitCommits,
FilterPath: gui.State.Modes.Filtering.Path, FilterPath: gui.State.Modes.Filtering.GetPath(),
IncludeRebaseCommits: false, IncludeRebaseCommits: false,
RefName: refName, RefName: refName,
}, },
@ -94,9 +94,9 @@ func (gui *Gui) switchToSubCommitsContext(refName string) error {
gui.State.SubCommits = commits gui.State.SubCommits = commits
gui.State.Panels.SubCommits.refName = refName gui.State.Panels.SubCommits.refName = refName
gui.State.Panels.SubCommits.SelectedLineIdx = 0 gui.State.Panels.SubCommits.SelectedLineIdx = 0
gui.Contexts.SubCommits.Context.SetParentContext(gui.currentSideContext()) gui.Contexts.SubCommits.SetParentContext(gui.currentSideContext())
return gui.pushContext(gui.Contexts.SubCommits.Context) return gui.pushContext(gui.Contexts.SubCommits)
} }
func (gui *Gui) handleSwitchToSubCommits() error { func (gui *Gui) handleSwitchToSubCommits() error {

View File

@ -32,5 +32,5 @@ func (gui *Gui) setSuggestions(suggestions []*types.Suggestion) {
gui.State.Suggestions = suggestions gui.State.Suggestions = suggestions
gui.State.Panels.Suggestions.SelectedLineIdx = 0 gui.State.Panels.Suggestions.SelectedLineIdx = 0
_ = gui.resetOrigin(view) _ = gui.resetOrigin(view)
_ = gui.Contexts.Suggestions.Context.HandleRender() _ = gui.Contexts.Suggestions.HandleRender()
} }

View File

@ -44,7 +44,7 @@ func (gui *Gui) refreshTags() error {
gui.State.Tags = tags gui.State.Tags = tags
return gui.postRefreshUpdate(gui.Contexts.Tags.Context) return gui.postRefreshUpdate(gui.Contexts.Tags)
} }
func (gui *Gui) handleCheckoutTag() error { func (gui *Gui) handleCheckoutTag() error {
@ -55,7 +55,7 @@ func (gui *Gui) handleCheckoutTag() error {
if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{}); err != nil { if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{}); err != nil {
return err return err
} }
return gui.pushContext(gui.Contexts.Branches.Context) return gui.pushContext(gui.Contexts.Branches)
} }
func (gui *Gui) handleDeleteTag() error { func (gui *Gui) handleDeleteTag() error {
@ -123,7 +123,7 @@ func (gui *Gui) handleCreateTag() error {
for i, tag := range gui.State.Tags { for i, tag := range gui.State.Tags {
if tag.Name == tagName { if tag.Name == tagName {
gui.State.Panels.Tags.SelectedLineIdx = i gui.State.Panels.Tags.SelectedLineIdx = i
if err := gui.Contexts.Tags.Context.HandleRender(); err != nil { if err := gui.Contexts.Tags.HandleRender(); err != nil {
gui.Log.Error(err) gui.Log.Error(err)
} }

View File

@ -17,7 +17,7 @@ func (gui *Gui) getViewNameForWindow(window string) string {
func (gui *Gui) getWindowForViewName(viewName string) string { func (gui *Gui) getWindowForViewName(viewName string) string {
if viewName == "commitFiles" { if viewName == "commitFiles" {
return gui.Contexts.CommitFiles.Context.GetWindowName() return gui.Contexts.CommitFiles.GetWindowName()
} }
return viewName return viewName