From dab78c8a632fa12a24db2247a5c7096c5166c91a Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 8 Dec 2019 21:23:51 +1100 Subject: [PATCH] stop the files panel from stealing focus whenever files are refreshed --- pkg/gui/files_panel.go | 18 +++++++++--------- pkg/gui/list_view.go | 4 ++-- pkg/gui/view_helpers.go | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 5f68f3fab..463db817e 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -27,15 +27,7 @@ func (gui *Gui) getSelectedFile(g *gocui.Gui) (*commands.File, error) { return gui.State.Files[selectedLine], nil } -func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View) error { - return gui.selectFile(false) -} - func (gui *Gui) selectFile(alreadySelected bool) error { - if _, err := gui.g.SetCurrentView("files"); err != nil { - return err - } - file, err := gui.getSelectedFile(gui.g) if err != nil { if err != gui.Errors.ErrNoFiles { @@ -221,6 +213,14 @@ func (gui *Gui) allFilesStaged() bool { return true } +func (gui *Gui) focusAndSelectFile(g *gocui.Gui, v *gocui.View) error { + if _, err := gui.g.SetCurrentView("files"); err != nil { + return err + } + + return gui.selectFile(false) +} + func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error { var err error if gui.allFilesStaged() { @@ -236,7 +236,7 @@ func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error { return err } - return gui.handleFileSelect(gui.g, v) + return gui.selectFile(false) } func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { diff --git a/pkg/gui/list_view.go b/pkg/gui/list_view.go index 4d72efc43..274976c4c 100644 --- a/pkg/gui/list_view.go +++ b/pkg/gui/list_view.go @@ -79,8 +79,8 @@ func (gui *Gui) getListViews() []*listView { viewName: "files", getItemsLength: func() int { return len(gui.State.Files) }, getSelectedLineIdxPtr: func() *int { return &gui.State.Panels.Files.SelectedLine }, - handleFocus: gui.wrappedHandler(func() error { return gui.selectFile(true) }), - handleItemSelect: gui.wrappedHandler(func() error { return gui.selectFile(true) }), + handleFocus: gui.focusAndSelectFile, + handleItemSelect: gui.focusAndSelectFile, handleClickSelectedItem: gui.handleFilePress, gui: gui, rendersToMainView: true, diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 6112a5422..bf25dbdbb 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -102,7 +102,7 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error { case "status": return gui.handleStatusSelect(g, v) case "files": - return gui.handleFileSelect(g, v) + return gui.focusAndSelectFile(g, v) case "branches": branchesView := gui.getBranchesView() switch branchesView.Context {