1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-26 09:00:57 +02:00

stop the files panel from stealing focus whenever files are refreshed

This commit is contained in:
Jesse Duffield 2019-12-08 21:23:51 +11:00
parent 3f4613feb0
commit dab78c8a63
3 changed files with 12 additions and 12 deletions

View File

@ -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 {

View File

@ -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,

View File

@ -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 {