summaryrefslogtreecommitdiffstats
path: root/pkg/gui/controllers
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2024-01-14 09:50:52 +1100
committerJesse Duffield <jessedduffield@gmail.com>2024-01-19 10:47:21 +1100
commit54bd94ad24ca24ca12fab59e9dbf0d79fe7681da (patch)
tree0dd7c0819d29aa38828486f3e5c6b0a017790c5b /pkg/gui/controllers
parent8840c1a2b75749724b2dc6e329c2e150db93bc5a (diff)
Add SetSelection function for list contexts and use it in most places
The only time we should call SetSelectedLineIdx is when we are happy for a select range to be retained which means things like moving the selected line index to top top/bottom or up/down a page as the user navigates. But in every other case we should now call SetSelection because that will set the selected index and cancel the range which is almost always what we want.
Diffstat (limited to 'pkg/gui/controllers')
-rw-r--r--pkg/gui/controllers/bisect_controller.go2
-rw-r--r--pkg/gui/controllers/branches_controller.go6
-rw-r--r--pkg/gui/controllers/filtering_menu_action.go2
-rw-r--r--pkg/gui/controllers/helpers/fixup_helper.go2
-rw-r--r--pkg/gui/controllers/helpers/refs_helper.go14
-rw-r--r--pkg/gui/controllers/helpers/search_helper.go4
-rw-r--r--pkg/gui/controllers/helpers/sub_commits_helper.go2
-rw-r--r--pkg/gui/controllers/list_controller.go2
-rw-r--r--pkg/gui/controllers/local_commits_controller.go2
-rw-r--r--pkg/gui/controllers/remote_branches_controller.go2
-rw-r--r--pkg/gui/controllers/remotes_controller.go2
-rw-r--r--pkg/gui/controllers/stash_controller.go2
-rw-r--r--pkg/gui/controllers/switch_to_diff_files_controller.go2
-rw-r--r--pkg/gui/controllers/tags_controller.go4
14 files changed, 25 insertions, 23 deletions
diff --git a/pkg/gui/controllers/bisect_controller.go b/pkg/gui/controllers/bisect_controller.go
index 7cb36ef26..bff603afb 100644
--- a/pkg/gui/controllers/bisect_controller.go
+++ b/pkg/gui/controllers/bisect_controller.go
@@ -265,7 +265,7 @@ func (self *BisectController) selectCurrentBisectCommit() {
// find index of commit with that sha, move cursor to that.
for i, commit := range self.c.Model().Commits {
if commit.Sha == info.GetCurrentSha() {
- self.context().SetSelectedLineIdx(i)
+ self.context().SetSelection(i)
_ = self.context().HandleFocus(types.OnFocusOpts{})
break
}
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go
index 866f3eae3..8e762d78b 100644
--- a/pkg/gui/controllers/branches_controller.go
+++ b/pkg/gui/controllers/branches_controller.go
@@ -424,7 +424,7 @@ func (self *BranchesController) createNewBranchWithName(newBranchName string) er
return self.c.Error(err)
}
- self.context().SetSelectedLineIdx(0)
+ self.context().SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
}
@@ -627,7 +627,7 @@ func (self *BranchesController) createSortMenu() error {
if self.c.GetAppState().LocalBranchSortOrder != sortOrder {
self.c.GetAppState().LocalBranchSortOrder = sortOrder
self.c.SaveAppStateAndLogError()
- self.c.Contexts().Branches.SetSelectedLineIdx(0)
+ self.c.Contexts().Branches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.BRANCHES}})
}
return nil
@@ -658,7 +658,7 @@ func (self *BranchesController) rename(branch *models.Branch) error {
// now that we've got our stuff again we need to find that branch and reselect it.
for i, newBranch := range self.c.Model().Branches {
if newBranch.Name == newBranchName {
- self.context().SetSelectedLineIdx(i)
+ self.context().SetSelection(i)
if err := self.context().HandleRender(); err != nil {
return err
}
diff --git a/pkg/gui/controllers/filtering_menu_action.go b/pkg/gui/controllers/filtering_menu_action.go
index 6a0f3b2db..d8525b99d 100644
--- a/pkg/gui/controllers/filtering_menu_action.go
+++ b/pkg/gui/controllers/filtering_menu_action.go
@@ -73,7 +73,7 @@ func (self *FilteringMenuAction) setFiltering(path string) error {
}
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() {
- self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
+ self.c.Contexts().LocalCommits.SetSelection(0)
self.c.Contexts().LocalCommits.FocusLine()
}})
}
diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go
index 35c8233b8..0a1bc713e 100644
--- a/pkg/gui/controllers/helpers/fixup_helper.go
+++ b/pkg/gui/controllers/helpers/fixup_helper.go
@@ -87,7 +87,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
_ = self.c.Refresh(types.RefreshOptions{Mode: types.SYNC, Scope: []types.RefreshableView{types.FILES}})
}
- self.c.Contexts().LocalCommits.SetSelectedLineIdx(index)
+ self.c.Contexts().LocalCommits.SetSelection(index)
return self.c.PushContext(self.c.Contexts().LocalCommits)
}
diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go
index 6d0d64983..4e4461526 100644
--- a/pkg/gui/controllers/helpers/refs_helper.go
+++ b/pkg/gui/controllers/helpers/refs_helper.go
@@ -44,9 +44,9 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars}
onSuccess := func() {
- self.c.Contexts().Branches.SetSelectedLineIdx(0)
- self.c.Contexts().ReflogCommits.SetSelectedLineIdx(0)
- self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
+ self.c.Contexts().Branches.SetSelection(0)
+ self.c.Contexts().ReflogCommits.SetSelection(0)
+ self.c.Contexts().LocalCommits.SetSelection(0)
// loading a heap of commits is slow so we limit them whenever doing a reset
self.c.Contexts().LocalCommits.SetLimitCommits(true)
}
@@ -107,8 +107,8 @@ func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string
return self.c.Error(err)
}
- self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
- self.c.Contexts().ReflogCommits.SetSelectedLineIdx(0)
+ self.c.Contexts().LocalCommits.SetSelection(0)
+ self.c.Contexts().ReflogCommits.SetSelection(0)
// loading a heap of commits is slow so we limit them whenever doing a reset
self.c.Contexts().LocalCommits.SetLimitCommits(true)
@@ -215,8 +215,8 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest
}
}
- self.c.Contexts().LocalCommits.SetSelectedLineIdx(0)
- self.c.Contexts().Branches.SetSelectedLineIdx(0)
+ self.c.Contexts().LocalCommits.SetSelection(0)
+ self.c.Contexts().Branches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
},
diff --git a/pkg/gui/controllers/helpers/search_helper.go b/pkg/gui/controllers/helpers/search_helper.go
index 4c4b6918c..9ceea2f90 100644
--- a/pkg/gui/controllers/helpers/search_helper.go
+++ b/pkg/gui/controllers/helpers/search_helper.go
@@ -216,7 +216,7 @@ func (self *SearchHelper) OnPromptContentChanged(searchString string) {
state := self.searchState()
switch context := state.Context.(type) {
case types.IFilterableContext:
- context.SetSelectedLineIdx(0)
+ context.SetSelection(0)
_ = context.GetView().SetOriginY(0)
context.SetFilter(searchString)
_ = self.c.PostRefreshUpdate(context)
@@ -232,7 +232,7 @@ func (self *SearchHelper) ReApplyFilter(context types.Context) {
if context == state.Context {
filterableContext, ok := context.(types.IFilterableContext)
if ok {
- filterableContext.SetSelectedLineIdx(0)
+ filterableContext.SetSelection(0)
_ = filterableContext.GetView().SetOriginY(0)
filterableContext.ReApplyFilter()
}
diff --git a/pkg/gui/controllers/helpers/sub_commits_helper.go b/pkg/gui/controllers/helpers/sub_commits_helper.go
index 7f5417cc3..b572aa45b 100644
--- a/pkg/gui/controllers/helpers/sub_commits_helper.go
+++ b/pkg/gui/controllers/helpers/sub_commits_helper.go
@@ -53,7 +53,7 @@ func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
self.refreshHelper.RefreshAuthors(commits)
subCommitsContext := self.c.Contexts().SubCommits
- subCommitsContext.SetSelectedLineIdx(0)
+ subCommitsContext.SetSelection(0)
subCommitsContext.SetParentContext(opts.Context)
subCommitsContext.SetWindowName(opts.Context.GetWindowName())
subCommitsContext.SetTitleRef(utils.TruncateWithEllipsis(opts.TitleRef, 50))
diff --git a/pkg/gui/controllers/list_controller.go b/pkg/gui/controllers/list_controller.go
index 1f3c743bc..9b7a740b5 100644
--- a/pkg/gui/controllers/list_controller.go
+++ b/pkg/gui/controllers/list_controller.go
@@ -160,7 +160,7 @@ func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error {
return nil
}
- self.context.GetList().SetSelectedLineIdx(newSelectedLineIdx)
+ self.context.GetList().SetSelection(newSelectedLineIdx)
if prevSelectedLineIdx == newSelectedLineIdx && alreadyFocused && self.context.GetOnClick() != nil {
return self.context.GetOnClick()()
diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go
index 97151f4fe..c484d2487 100644
--- a/pkg/gui/controllers/local_commits_controller.go
+++ b/pkg/gui/controllers/local_commits_controller.go
@@ -459,7 +459,7 @@ func (self *LocalCommitsController) startInteractiveRebaseWithEdit(
return c.Sha == selectedCommit.Sha
})
if ok {
- self.context().SetSelectedLineIdx(index)
+ self.context().SetSelection(index)
}
}})
})
diff --git a/pkg/gui/controllers/remote_branches_controller.go b/pkg/gui/controllers/remote_branches_controller.go
index 04afd6415..d6f9e9036 100644
--- a/pkg/gui/controllers/remote_branches_controller.go
+++ b/pkg/gui/controllers/remote_branches_controller.go
@@ -132,7 +132,7 @@ func (self *RemoteBranchesController) createSortMenu() error {
if self.c.GetAppState().RemoteBranchSortOrder != sortOrder {
self.c.GetAppState().RemoteBranchSortOrder = sortOrder
self.c.SaveAppStateAndLogError()
- self.c.Contexts().RemoteBranches.SetSelectedLineIdx(0)
+ self.c.Contexts().RemoteBranches.SetSelection(0)
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.REMOTES}})
}
return nil
diff --git a/pkg/gui/controllers/remotes_controller.go b/pkg/gui/controllers/remotes_controller.go
index d0f643eec..47f14417e 100644
--- a/pkg/gui/controllers/remotes_controller.go
+++ b/pkg/gui/controllers/remotes_controller.go
@@ -106,7 +106,7 @@ func (self *RemotesController) enter(remote *models.Remote) error {
newSelectedLine = -1
}
remoteBranchesContext := self.c.Contexts().RemoteBranches
- remoteBranchesContext.SetSelectedLineIdx(newSelectedLine)
+ remoteBranchesContext.SetSelection(newSelectedLine)
remoteBranchesContext.SetTitleRef(remote.Name)
remoteBranchesContext.SetParentContext(self.Context())
remoteBranchesContext.GetView().TitlePrefix = self.Context().GetView().TitlePrefix
diff --git a/pkg/gui/controllers/stash_controller.go b/pkg/gui/controllers/stash_controller.go
index 5d74e10af..acd66cd31 100644
--- a/pkg/gui/controllers/stash_controller.go
+++ b/pkg/gui/controllers/stash_controller.go
@@ -189,7 +189,7 @@ func (self *StashController) handleRenameStashEntry(stashEntry *models.StashEntr
if err != nil {
return err
}
- self.context().SetSelectedLineIdx(0) // Select the renamed stash
+ self.context().SetSelection(0) // Select the renamed stash
self.context().FocusLine()
return nil
},
diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go
index 7143a8805..af2b38984 100644
--- a/pkg/gui/controllers/switch_to_diff_files_controller.go
+++ b/pkg/gui/controllers/switch_to_diff_files_controller.go
@@ -77,7 +77,7 @@ func (self *SwitchToDiffFilesController) Context() types.Context {
func (self *SwitchToDiffFilesController) viewFiles(opts SwitchToCommitFilesContextOpts) error {
diffFilesContext := self.diffFilesContext
- diffFilesContext.SetSelectedLineIdx(0)
+ diffFilesContext.SetSelection(0)
diffFilesContext.SetRef(opts.Ref)
diffFilesContext.SetTitleRef(opts.Ref.Description())
diffFilesContext.SetCanRebase(opts.CanRebase)
diff --git a/pkg/gui/controllers/tags_controller.go b/pkg/gui/controllers/tags_controller.go
index dcbef4d2c..e96dde2e4 100644
--- a/pkg/gui/controllers/tags_controller.go
+++ b/pkg/gui/controllers/tags_controller.go
@@ -210,7 +210,9 @@ func (self *TagsController) createResetMenu(tag *models.Tag) error {
func (self *TagsController) create() error {
// leaving commit SHA blank so that we're just creating the tag for the current commit
- return self.c.Helpers().Tags.OpenCreateTagPrompt("", func() { self.context().SetSelectedLineIdx(0) })
+ return self.c.Helpers().Tags.OpenCreateTagPrompt("", func() {
+ self.context().SetSelection(0)
+ })
}
func (self *TagsController) withSelectedTag(f func(tag *models.Tag) error) func() error {