Files
lazygit/pkg/gui/extras_panel.go
Stefan HallerandClaude Opus 5.5 76064a302b Replace GetAppState and SaveAppState with ReadAppState and UpdateAppState
Each lazygit instance reads state.yml once at startup. Callers change
that copy and then save all of it. So an instance doesn't see what
other instances changed after it started, and when it saves, it
overwrites their changes.

To fix this, the following commits make ReadAppState read the file and
UpdateAppState apply the change to what it finds in the file. For this
to work, callers must express a change as an operation on the current
state: add a command to the front of the history, remove a history
entry by its value, move the current repo to the front of the recent
repos. The call sites already compute the new value from the current
one; move that code into the update function.

This commit still works on the in-memory copy, so it doesn't change
behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:10:58 +01:00

122 lines
3.3 KiB
Go

package gui
import (
"io"
"github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/context"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
func (gui *Gui) handleCreateExtrasMenuPanel() error {
return gui.c.Menu(types.CreateMenuOptions{
Title: gui.c.Tr.CommandLog,
Items: []*types.MenuItem{
{
Label: gui.c.Tr.ToggleShowCommandLog,
Keys: []gocui.Key{gocui.NewKeyRune('t')},
OnPress: func() error {
currentContext := gui.c.Context().CurrentStatic()
if gui.c.State().GetShowExtrasWindow() && currentContext.GetKey() == context.COMMAND_LOG_CONTEXT_KEY {
gui.c.Context().Pop()
}
show := !gui.c.State().GetShowExtrasWindow()
gui.c.State().SetShowExtrasWindow(show)
gui.c.UpdateAppState(func(state *config.AppState) {
state.HideCommandLog = !show
})
return nil
},
},
{
Label: gui.c.Tr.FocusCommandLog,
Keys: []gocui.Key{gocui.NewKeyRune('f')},
OnPress: gui.handleFocusCommandLog,
},
},
})
}
func (gui *Gui) handleFocusCommandLog() error {
gui.c.State().SetShowExtrasWindow(true)
// TODO: is this necessary? Can't I just call 'return from context'?
gui.State.Contexts.CommandLog.SetParentContext(gui.c.Context().CurrentSide())
gui.c.Context().Push(gui.State.Contexts.CommandLog, types.OnFocusOpts{})
return nil
}
func (gui *Gui) scrollUpExtra() error {
gui.Views.Extras.Autoscroll = false
gui.scrollUpView(gui.Views.Extras)
return nil
}
func (gui *Gui) scrollDownExtra() error {
gui.Views.Extras.Autoscroll = false
gui.scrollDownView(gui.Views.Extras)
return nil
}
func (gui *Gui) pageUpExtrasPanel() error {
gui.Views.Extras.Autoscroll = false
gui.Views.Extras.ScrollUp(gui.Contexts().CommandLog.GetViewTrait().PageDelta())
return nil
}
func (gui *Gui) pageDownExtrasPanel() error {
gui.Views.Extras.Autoscroll = false
gui.Views.Extras.ScrollDown(gui.Contexts().CommandLog.GetViewTrait().PageDelta())
return nil
}
func (gui *Gui) goToExtrasPanelTop() error {
gui.Views.Extras.Autoscroll = false
gui.Views.Extras.ScrollUp(gui.Views.Extras.ViewLinesHeight())
return nil
}
func (gui *Gui) goToExtrasPanelBottom() error {
gui.Views.Extras.Autoscroll = true
gui.Views.Extras.ScrollDown(gui.Views.Extras.ViewLinesHeight())
return nil
}
func (gui *Gui) getCmdWriter() io.Writer {
return &prefixWriter{writer: gui.Views.Extras, prefix: style.FgMagenta.Sprintf("\n\n%s\n", gui.c.Tr.GitOutput)}
}
// Ensures that the first write is preceded by writing a prefix.
// This allows us to say 'Git output:' before writing the actual git output.
// We could just write directly to the view in this package before running the command but we already have code in the commands package that writes to the same view beforehand (with the command it's about to run) so things would be out of order.
type prefixWriter struct {
prefix string
prefixWritten bool
writer io.Writer
}
func (self *prefixWriter) Write(p []byte) (int, error) {
if !self.prefixWritten {
self.prefixWritten = true
// assuming we can write this prefix in one go
n, err := self.writer.Write([]byte(self.prefix))
if err != nil {
return n, err
}
}
return self.writer.Write(p)
}