Remove return value of Focus-related functions

This commit is contained in:
Stefan Haller 2024-09-04 14:26:15 +02:00
parent 8edcd71234
commit 8302575078
24 changed files with 73 additions and 96 deletions

View file

@ -183,9 +183,7 @@ func (self *ContextMgr) deactivate(c types.Context, opts types.OnFocusLostOpts)
view.Visible = false
}
if err := c.HandleFocusLost(opts); err != nil {
return err
}
c.HandleFocusLost(opts)
return nil
}
@ -219,9 +217,7 @@ func (self *ContextMgr) Activate(c types.Context, opts types.OnFocusOpts) error
self.gui.c.GocuiGui().Cursor = v.Editable
if err := c.HandleFocus(opts); err != nil {
return err
}
c.HandleFocus(opts)
return nil
}

View file

@ -31,8 +31,8 @@ type BaseContext struct {
}
type (
onFocusFn = func(types.OnFocusOpts) error
onFocusLostFn = func(types.OnFocusLostOpts) error
onFocusFn = func(types.OnFocusOpts)
onFocusLostFn = func(types.OnFocusLostOpts)
)
var _ types.IBaseContext = &BaseContext{}

View file

@ -72,22 +72,22 @@ func formatListFooter(selectedLineIdx int, length int) string {
return fmt.Sprintf("%d of %d", selectedLineIdx+1, length)
}
func (self *ListContextTrait) HandleFocus(opts types.OnFocusOpts) error {
func (self *ListContextTrait) HandleFocus(opts types.OnFocusOpts) {
self.FocusLine()
self.GetViewTrait().SetHighlight(self.list.Len() > 0)
return self.Context.HandleFocus(opts)
self.Context.HandleFocus(opts)
}
func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) error {
func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) {
self.GetViewTrait().SetOriginX(0)
if self.refreshViewportOnChange {
self.refreshViewport()
}
return self.Context.HandleFocusLost(opts)
self.Context.HandleFocusLost(opts)
}
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
@ -114,7 +114,8 @@ func (self *ListContextTrait) HandleRender() {
func (self *ListContextTrait) OnSearchSelect(selectedLineIdx int) error {
self.GetList().SetSelection(self.ViewIndexToModelIndex(selectedLineIdx))
return self.HandleFocus(types.OnFocusOpts{})
self.HandleFocus(types.OnFocusOpts{})
return nil
}
func (self *ListContextTrait) IsItemVisible(item types.HasUrn) bool {

View file

@ -92,11 +92,9 @@ func (self *PatchExplorerContext) Render(isFocused bool) {
self.c.Render()
}
func (self *PatchExplorerContext) Focus() error {
func (self *PatchExplorerContext) Focus() {
self.FocusSelection()
self.c.Render()
return nil
}
func (self *PatchExplorerContext) setContent(isFocused bool) {

View file

@ -31,31 +31,26 @@ func NewDisplayContext(key types.ContextKey, view *gocui.View, windowName string
)
}
func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) error {
func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) {
if self.highlightOnFocus {
self.GetViewTrait().SetHighlight(true)
}
if self.onFocusFn != nil {
if err := self.onFocusFn(opts); err != nil {
return err
}
self.onFocusFn(opts)
}
if self.onRenderToMainFn != nil {
self.onRenderToMainFn()
}
return nil
}
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) error {
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
self.GetViewTrait().SetHighlight(false)
self.view.SetOriginX(0)
if self.onFocusLostFn != nil {
return self.onFocusLostFn(opts)
self.onFocusLostFn(opts)
}
return nil
}
func (self *SimpleContext) HandleRender() {

View file

@ -23,10 +23,10 @@ func (self *baseController) GetOnRenderToMain() func() {
return nil
}
func (self *baseController) GetOnFocus() func(types.OnFocusOpts) error {
func (self *baseController) GetOnFocus() func(types.OnFocusOpts) {
return nil
}
func (self *baseController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
func (self *baseController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return nil
}

View file

@ -290,7 +290,7 @@ func (self *BisectController) selectCurrentBisectCommit() {
for i, commit := range self.c.Model().Commits {
if commit.Hash == info.GetCurrentHash() {
self.context().SetSelection(i)
_ = self.context().HandleFocus(types.OnFocusOpts{})
self.context().HandleFocus(types.OnFocusOpts{})
break
}
}

View file

@ -26,10 +26,9 @@ func (self *CommandLogController) GetKeybindings(opts types.KeybindingsOpts) []*
return bindings
}
func (self *CommandLogController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
func (self *CommandLogController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(types.OnFocusLostOpts) {
self.c.Views().Extras.Autoscroll = true
return nil
}
}

View file

@ -69,10 +69,9 @@ func (self *CommitMessageController) GetMouseKeybindings(opts types.KeybindingsO
}
}
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
func (self *CommitMessageController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(types.OnFocusLostOpts) {
self.context().RenderCommitLength()
return nil
}
}

View file

@ -59,10 +59,9 @@ func (self *ConfirmationController) GetKeybindings(opts types.KeybindingsOpts) [
return bindings
}
func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
func (self *ConfirmationController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(types.OnFocusLostOpts) {
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()
return nil
}
}

View file

@ -456,7 +456,8 @@ func (self *FilesController) press(nodes []*filetree.FileNode) error {
return err
}
return self.context().HandleFocus(types.OnFocusOpts{})
self.context().HandleFocus(types.OnFocusOpts{})
return nil
}
func (self *FilesController) Context() types.Context {
@ -516,7 +517,8 @@ func (self *FilesController) toggleStagedAll() error {
return err
}
return self.context().HandleFocus(types.OnFocusOpts{})
self.context().HandleFocus(types.OnFocusOpts{})
return nil
}
func (self *FilesController) toggleStagedAllWithLock() error {

View file

@ -370,7 +370,7 @@ func (self *ConfirmationHelper) layoutMenuPrompt(contentWidth int) int {
// Then we need to refocus to ensure the cursor is in the right place in
// the view.
_ = self.c.Contexts().Menu.HandleFocus(types.OnFocusOpts{})
self.c.Contexts().Menu.HandleFocus(types.OnFocusOpts{})
}
return len(promptLines)
}

View file

@ -73,7 +73,8 @@ func (self *ListController) HandleScrollDown() error {
func (self *ListController) scrollHorizontal(scrollFunc func()) error {
scrollFunc()
return self.context.HandleFocus(types.OnFocusOpts{})
self.context.HandleFocus(types.OnFocusOpts{})
return nil
}
func (self *ListController) handleLineChange(change int) error {
@ -115,7 +116,7 @@ func (self *ListController) handleLineChangeAux(f func(int), change int) error {
}
if cursorMoved || rangeBefore != rangeAfter {
return self.context.HandleFocus(types.OnFocusOpts{})
self.context.HandleFocus(types.OnFocusOpts{})
}
return nil
@ -142,7 +143,8 @@ func (self *ListController) HandleToggleRangeSelect() error {
list.ToggleStickyRange()
return self.context.HandleFocus(types.OnFocusOpts{})
self.context.HandleFocus(types.OnFocusOpts{})
return nil
}
func (self *ListController) HandleRangeSelectDown() error {
@ -171,7 +173,8 @@ func (self *ListController) HandleClick(opts gocui.ViewMouseBindingOpts) error {
if prevSelectedLineIdx == newSelectedLineIdx && alreadyFocused && self.context.GetOnClick() != nil {
return self.context.GetOnClick()()
}
return self.context.HandleFocus(types.OnFocusOpts{})
self.context.HandleFocus(types.OnFocusOpts{})
return nil
}
func (self *ListController) pushContextIfNotFocused() error {

View file

@ -1175,8 +1175,8 @@ func (self *LocalCommitsController) handleOpenLogMenu() error {
})
}
func (self *LocalCommitsController) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
func (self *LocalCommitsController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
context := self.context()
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
@ -1184,8 +1184,6 @@ func (self *LocalCommitsController) GetOnFocus() func(types.OnFocusOpts) error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
})
}
return nil
}
}

View file

@ -59,13 +59,12 @@ func (self *MenuController) GetOnClick() func() error {
return self.withItemGraceful(self.press)
}
func (self *MenuController) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
func (self *MenuController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
selectedMenuItem := self.context().GetSelected()
if selectedMenuItem != nil {
self.c.Views().Tooltip.SetContent(self.c.Helpers().Confirmation.TooltipForMenuItem(selectedMenuItem))
}
return nil
}
}

View file

@ -147,25 +147,21 @@ func (self *MergeConflictsController) GetMouseKeybindings(opts types.Keybindings
}
}
func (self *MergeConflictsController) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
func (self *MergeConflictsController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
self.c.Views().MergeConflicts.Wrap = false
self.c.Helpers().MergeConflicts.Render()
self.context().SetSelectedLineRange()
return nil
}
}
func (self *MergeConflictsController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
func (self *MergeConflictsController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(types.OnFocusLostOpts) {
self.context().SetUserScrolling(false)
self.context().GetState().ResetConflictSelection()
self.c.Views().MergeConflicts.Wrap = true
return nil
}
}

View file

@ -62,24 +62,24 @@ func (self *PatchBuildingController) GetMouseKeybindings(opts types.KeybindingsO
return []*gocui.ViewMouseBinding{}
}
func (self *PatchBuildingController) GetOnFocus() func(types.OnFocusOpts) error {
return func(opts types.OnFocusOpts) error {
func (self *PatchBuildingController) GetOnFocus() func(types.OnFocusOpts) {
return func(opts types.OnFocusOpts) {
// no need to change wrap on the secondary view because it can't be interacted with
self.c.Views().PatchBuilding.Wrap = false
return self.c.Helpers().PatchBuilding.RefreshPatchBuildingPanel(opts)
// Swallowing the error here for now. This will change shortly to not
// return an error any more.
_ = self.c.Helpers().PatchBuilding.RefreshPatchBuildingPanel(opts) // FIXME
}
}
func (self *PatchBuildingController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(opts types.OnFocusLostOpts) error {
func (self *PatchBuildingController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(opts types.OnFocusLostOpts) {
self.c.Views().PatchBuilding.Wrap = true
if self.c.Git().Patch.PatchBuilder.IsEmpty() {
self.c.Git().Patch.PatchBuilder.Reset()
}
return nil
}
}

View file

@ -52,18 +52,16 @@ func (self *SnakeController) Context() types.Context {
return self.c.Contexts().Snake
}
func (self *SnakeController) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
func (self *SnakeController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
self.c.Helpers().Snake.StartGame()
return nil
}
}
func (self *SnakeController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
func (self *SnakeController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(types.OnFocusLostOpts) {
self.c.Helpers().Snake.ExitGame()
self.c.Helpers().Window.MoveToTopOfWindow(self.c.Contexts().Submodules)
return nil
}
}

View file

@ -116,18 +116,17 @@ func (self *StagingController) GetMouseKeybindings(opts types.KeybindingsOpts) [
return []*gocui.ViewMouseBinding{}
}
func (self *StagingController) GetOnFocus() func(types.OnFocusOpts) error {
return func(opts types.OnFocusOpts) error {
func (self *StagingController) GetOnFocus() func(types.OnFocusOpts) {
return func(opts types.OnFocusOpts) {
self.c.Views().Staging.Wrap = false
self.c.Views().StagingSecondary.Wrap = false
self.c.Helpers().Staging.RefreshStagingPanel(opts)
return nil
}
}
func (self *StagingController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(opts types.OnFocusLostOpts) error {
func (self *StagingController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(opts types.OnFocusLostOpts) {
self.context.SetState(nil)
if opts.NewContextKey != self.otherContext.GetKey() {
@ -136,7 +135,6 @@ func (self *StagingController) GetOnFocusLost() func(types.OnFocusLostOpts) erro
self.c.Contexts().Staging.Render(false)
self.c.Contexts().StagingSecondary.Render(false)
}
return nil
}
}

View file

@ -62,8 +62,8 @@ func (self *SubCommitsController) GetOnRenderToMain() func() {
}
}
func (self *SubCommitsController) GetOnFocus() func(types.OnFocusOpts) error {
return func(types.OnFocusOpts) error {
func (self *SubCommitsController) GetOnFocus() func(types.OnFocusOpts) {
return func(types.OnFocusOpts) {
context := self.context()
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
@ -71,7 +71,5 @@ func (self *SubCommitsController) GetOnFocus() func(types.OnFocusOpts) error {
return self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.SUB_COMMITS}})
})
}
return nil
}
}

View file

@ -75,10 +75,9 @@ func (self *SuggestionsController) switchToConfirmation() error {
return self.c.Context().Replace(self.c.Contexts().Confirmation)
}
func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) error {
return func(types.OnFocusLostOpts) error {
func (self *SuggestionsController) GetOnFocusLost() func(types.OnFocusLostOpts) {
return func(types.OnFocusLostOpts) {
self.c.Helpers().Confirmation.DeactivateConfirmationPrompt()
return nil
}
}

View file

@ -28,5 +28,6 @@ func (self *ToggleWhitespaceAction) Call() error {
self.c.GetAppState().IgnoreWhitespaceInDiffView = !self.c.GetAppState().IgnoreWhitespaceInDiffView
self.c.SaveAppStateAndLogError()
return self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{})
self.c.Context().CurrentSide().HandleFocus(types.OnFocusOpts{})
return nil
}

View file

@ -96,15 +96,15 @@ type IBaseContext interface {
AddOnClickFn(func() error)
AddOnRenderToMainFn(func())
AddOnFocusFn(func(OnFocusOpts) error)
AddOnFocusLostFn(func(OnFocusLostOpts) error)
AddOnFocusFn(func(OnFocusOpts))
AddOnFocusLostFn(func(OnFocusLostOpts))
}
type Context interface {
IBaseContext
HandleFocus(opts OnFocusOpts) error
HandleFocusLost(opts OnFocusLostOpts) error
HandleFocus(opts OnFocusOpts)
HandleFocusLost(opts OnFocusLostOpts)
HandleRender()
HandleRenderToMain()
}
@ -179,7 +179,7 @@ type IPatchExplorerContext interface {
GetIncludedLineIndices() []int
RenderAndFocus(isFocused bool)
Render(isFocused bool)
Focus() error
Focus()
GetContentToRender(isFocused bool) string
NavigateTo(isFocused bool, selectedLineIdx int)
GetMutex() *deadlock.Mutex
@ -233,8 +233,8 @@ type HasKeybindings interface {
GetMouseKeybindings(opts KeybindingsOpts) []*gocui.ViewMouseBinding
GetOnClick() func() error
GetOnRenderToMain() func()
GetOnFocus() func(OnFocusOpts) error
GetOnFocusLost() func(OnFocusLostOpts) error
GetOnFocus() func(OnFocusOpts)
GetOnFocusLost() func(OnFocusLostOpts)
}
type IController interface {

View file

@ -134,9 +134,7 @@ func (gui *Gui) postRefreshUpdate(c types.Context) error {
c.HandleRender()
if gui.currentViewName() == c.GetViewName() {
if err := c.HandleFocus(types.OnFocusOpts{}); err != nil {
return err
}
c.HandleFocus(types.OnFocusOpts{})
}
return nil