Remove error return value from functions that always return nil

Originally I thought we'd benefit from this change in this branch; turns
out that we didn't after all, because we changed the approach, but it's
a nice cleanup anyway, so we include it here.
This commit is contained in:
Stefan Haller 2026-08-24 09:43:43 +02:00
parent 8924bca76f
commit c840013ca3
14 changed files with 46 additions and 56 deletions

View file

@ -13,14 +13,14 @@ func TestMouseReleaseDoesNotBreakDoubleClickDetection(t *testing.T) {
g := newTestGui(t)
view, _ := g.SetView("list", 0, 0, 20, 10, 0)
doubleClicks := []bool{}
assert.NoError(t, g.SetViewClickBinding(&ViewMouseBinding{
g.SetViewClickBinding(&ViewMouseBinding{
ViewName: "list",
Key: MouseLeft,
Handler: func(opts ViewMouseBindingOpts) error {
doubleClicks = append(doubleClicks, opts.IsDoubleClick)
return nil
},
}))
})
for _, event := range []GocuiEvent{
gocuiEventFromTcellEvent(tcell.NewEventMouse(view.x0+1, view.y0+1, tcell.ButtonPrimary, tcell.ModNone)),

View file

@ -675,19 +675,15 @@ func (g *Gui) DeleteViewKeybindings(viewname string) {
}
// SetTabClickBinding sets a binding for a tab click event
func (g *Gui) SetTabClickBinding(viewName string, handler tabClickHandler) error {
func (g *Gui) SetTabClickBinding(viewName string, handler tabClickHandler) {
g.tabClickBindings = append(g.tabClickBindings, &tabClickBinding{
viewName: viewName,
handler: handler,
})
return nil
}
func (g *Gui) SetViewClickBinding(binding *ViewMouseBinding) error {
func (g *Gui) SetViewClickBinding(binding *ViewMouseBinding) {
g.viewMouseBindings = append(g.viewMouseBindings, binding)
return nil
}
// captureMouse routes subsequent mouse events to view until the mouse button is

View file

@ -36,7 +36,7 @@ func TestMouseCaptureRoutesMotionAndReleaseOutsideView(t *testing.T) {
},
},
} {
assert.NoError(t, g.SetViewClickBinding(binding))
g.SetViewClickBinding(binding)
}
g.captureMouse(view)
@ -69,7 +69,7 @@ func TestPrimaryMouseDragStaysWithPressedView(t *testing.T) {
receivedBy := ""
for _, viewName := range []string{"left", "right"} {
assert.NoError(t, g.SetViewClickBinding(&ViewMouseBinding{
g.SetViewClickBinding(&ViewMouseBinding{
ViewName: viewName,
Key: MouseLeft,
Modifier: ModMotion,
@ -77,7 +77,7 @@ func TestPrimaryMouseDragStaysWithPressedView(t *testing.T) {
receivedBy = viewName
return nil
},
}))
})
}
assert.NoError(t, g.onKey(&GocuiEvent{
@ -102,10 +102,10 @@ func TestPrimaryMouseDragDoesNotActivateTabs(t *testing.T) {
view.Tabs = []string{"first", "second"}
clickedTabs := []int{}
assert.NoError(t, g.SetTabClickBinding("tabs", func(tabIndex int) error {
g.SetTabClickBinding("tabs", func(tabIndex int) error {
clickedTabs = append(clickedTabs, tabIndex)
return nil
}))
})
assert.NoError(t, g.onKey(&GocuiEvent{
Type: eventMouse,
@ -172,7 +172,7 @@ func TestCancelMouseCaptureSuppressesRemainingGesture(t *testing.T) {
_, _ = g.SetView("right", 21, 0, 41, 10, 0)
receivedBy := ""
for _, viewName := range []string{"left", "right"} {
assert.NoError(t, g.SetViewClickBinding(&ViewMouseBinding{
g.SetViewClickBinding(&ViewMouseBinding{
ViewName: viewName,
Key: MouseLeft,
Modifier: ModMotion,
@ -180,7 +180,7 @@ func TestCancelMouseCaptureSuppressesRemainingGesture(t *testing.T) {
receivedBy = viewName
return nil
},
}))
})
}
g.captureMouse(left)

View file

@ -44,5 +44,6 @@ func (self *FilterController) GetKeybindings(opts types.KeybindingsOpts) []*type
}
func (self *FilterController) OpenFilterPrompt() error {
return self.c.Helpers().Search.OpenFilterPrompt(self.context)
self.c.Helpers().Search.OpenFilterPrompt(self.context)
return nil
}

View file

@ -29,7 +29,7 @@ func NewSearchHelper(
}
}
func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) error {
func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) {
state := self.searchState()
state.PrevSearchIndex = -1
@ -44,10 +44,10 @@ func (self *SearchHelper) OpenFilterPrompt(context types.IFilterableContext) err
self.c.Context().Push(self.c.Contexts().Search, types.OnFocusOpts{})
return self.c.ResetKeybindings()
self.c.ResetKeybindings()
}
func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) error {
func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) {
state := self.searchState()
state.PrevSearchIndex = -1
@ -61,7 +61,7 @@ func (self *SearchHelper) OpenSearchPrompt(context types.ISearchableContext) err
self.c.Context().Push(self.c.Contexts().Search, types.OnFocusOpts{})
return self.c.ResetKeybindings()
self.c.ResetKeybindings()
}
func (self *SearchHelper) DisplayFilterStatus(context types.IFilterableContext) {
@ -103,10 +103,11 @@ func (self *SearchHelper) promptContent() string {
return self.c.Contexts().Search.GetView().TextArea.GetContent()
}
func (self *SearchHelper) Confirm() error {
func (self *SearchHelper) Confirm() {
state := self.searchState()
if self.promptContent() == "" {
return self.CancelPrompt()
self.CancelPrompt()
return
}
switch state.SearchType() {
@ -118,7 +119,7 @@ func (self *SearchHelper) Confirm() error {
self.c.Context().Pop()
}
return self.c.ResetKeybindings()
self.c.ResetKeybindings()
}
func (self *SearchHelper) ConfirmFilter() {
@ -175,12 +176,12 @@ func modelSearchResults(context types.ISearchableContext) []gocui.SearchPosition
return context.ModelSearchResults(normalizedSearchStr, caseSensitive)
}
func (self *SearchHelper) CancelPrompt() error {
func (self *SearchHelper) CancelPrompt() {
self.Cancel()
self.c.Context().Pop()
return self.c.ResetKeybindings()
self.c.ResetKeybindings()
}
func (self *SearchHelper) ScrollHistory(scrollIncrement int) {

View file

@ -1684,7 +1684,8 @@ func (self *LocalCommitsController) openSearch() error {
self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
}
return self.c.Helpers().Search.OpenSearchPrompt(self.context())
self.c.Helpers().Search.OpenSearchPrompt(self.context())
return nil
}
func (self *LocalCommitsController) handleOpenLogMenu() error {

View file

@ -109,7 +109,8 @@ func (self *MainViewController) openSearch() error {
if manager := self.c.GetViewBufferManagerForView(self.context.GetView()); manager != nil {
manager.ReadToEnd(func() {
self.c.OnUIThread(func() error {
return self.c.Helpers().Search.OpenSearchPrompt(self.context)
self.c.Helpers().Search.OpenSearchPrompt(self.context)
return nil
})
})
}

View file

@ -37,12 +37,13 @@ func (self *SearchController) GetKeybindings(opts types.KeybindingsOpts) []*type
return []*types.Binding{
{
Keys: opts.GetKeys(opts.Config.Universal.StartSearch),
Handler: self.OpenSearchPrompt,
Handler: self.openSearchPrompt,
Description: self.c.Tr.StartSearch,
},
}
}
func (self *SearchController) OpenSearchPrompt() error {
return self.c.Helpers().Search.OpenSearchPrompt(self.context)
func (self *SearchController) openSearchPrompt() error {
self.c.Helpers().Search.OpenSearchPrompt(self.context)
return nil
}

View file

@ -51,11 +51,13 @@ func (self *SearchPromptController) context() types.Context {
}
func (self *SearchPromptController) confirm() error {
return self.c.Helpers().Search.Confirm()
self.c.Helpers().Search.Confirm()
return nil
}
func (self *SearchPromptController) cancel() error {
return self.c.Helpers().Search.CancelPrompt()
self.c.Helpers().Search.CancelPrompt()
return nil
}
func (self *SearchPromptController) prevHistory() error {

View file

@ -368,10 +368,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
contextToPush := gui.resetState(startArgs)
gui.resetHelpersAndControllers()
if err := gui.resetKeybindings(); err != nil {
return err
}
gui.resetKeybindings()
gui.g.SetFocusHandler(func(Focused bool) error {
if Focused {
@ -383,9 +380,7 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
gui.c.Log.Info("User config changed - reloading")
reloadErr = gui.onUserConfigLoaded()
gui.reloadSidePanels()
if err := gui.resetKeybindings(); err != nil {
return err
}
gui.resetKeybindings()
if err := gui.checkForChangedConfigsThatDontAutoReload(oldConfig, gui.Config.GetUserConfig()); err != nil {
return err

View file

@ -201,8 +201,8 @@ func (self *guiCommon) CallKeybindingHandler(binding *types.Binding) error {
return self.gui.callKeybindingHandler(binding)
}
func (self *guiCommon) ResetKeybindings() error {
return self.gui.resetKeybindings()
func (self *guiCommon) ResetKeybindings() {
self.gui.resetKeybindings()
}
func (self *guiCommon) IsAnyModeActive() bool {

View file

@ -351,7 +351,7 @@ func (gui *Gui) GetInitialKeybindingsWithCustomCommands() ([]*types.Binding, []*
return bindings, mouseBindings
}
func (gui *Gui) resetKeybindings() error {
func (gui *Gui) resetKeybindings() {
gui.g.DeleteAllKeybindings()
bindings, mouseBindings := gui.GetInitialKeybindingsWithCustomCommands()
@ -361,9 +361,7 @@ func (gui *Gui) resetKeybindings() error {
}
for _, binding := range mouseBindings {
if err := gui.SetMouseKeybinding(binding); err != nil {
return err
}
gui.SetMouseKeybinding(binding)
}
for _, values := range gui.viewTabMap() {
@ -373,13 +371,9 @@ func (gui *Gui) resetKeybindings() error {
return gui.onViewTabClick(gui.helpers.Window.WindowForView(viewName), tabIndex)
}
if err := gui.g.SetTabClickBinding(viewName, tabClickCallback); err != nil {
return err
}
gui.g.SetTabClickBinding(viewName, tabClickCallback)
}
}
return nil
}
func (gui *Gui) SetKeybinding(binding *types.Binding) {
@ -392,8 +386,8 @@ func (gui *Gui) SetKeybinding(binding *types.Binding) {
}
}
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) error {
return gui.g.SetViewClickBinding(binding)
func (gui *Gui) SetMouseKeybinding(binding *gocui.ViewMouseBinding) {
gui.g.SetViewClickBinding(binding)
}
func (gui *Gui) callKeybindingHandler(binding *types.Binding) error {

View file

@ -80,9 +80,7 @@ func (gui *Gui) createMenu(opts types.CreateMenuOptions) error {
gui.Views.Tooltip.Visible = true
// resetting keybindings so that the menu-specific keybindings are registered
if err := gui.resetKeybindings(); err != nil {
return err
}
gui.resetKeybindings()
gui.c.PostRefreshUpdate(gui.State.Contexts.Menu)

View file

@ -145,7 +145,7 @@ type IGuiCommon interface {
KeybindingsOpts() KeybindingsOpts
CallKeybindingHandler(binding *Binding) error
ResetKeybindings() error
ResetKeybindings()
// hopefully we can remove this once we've moved all our keybinding stuff out of the gui god struct.
GetInitialKeybindingsWithCustomCommands() ([]*Binding, []*gocui.ViewMouseBinding)