1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/filtering.go
2022-03-17 19:13:40 +11:00

57 lines
1.3 KiB
Go

package gui
import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
func (gui *Gui) validateNotInFilterMode() bool {
if gui.State.Modes.Filtering.Active() {
_ = gui.c.Ask(types.AskOpts{
Title: gui.c.Tr.MustExitFilterModeTitle,
Prompt: gui.c.Tr.MustExitFilterModePrompt,
HandleConfirm: gui.exitFilterMode,
})
return false
}
return true
}
func (gui *Gui) outsideFilterMode(f func() error) func() error {
return func() error {
if !gui.validateNotInFilterMode() {
return nil
}
return f()
}
}
func (gui *Gui) exitFilterMode() error {
return gui.clearFiltering()
}
func (gui *Gui) clearFiltering() error {
gui.State.Modes.Filtering.Reset()
if gui.State.ScreenMode == SCREEN_HALF {
gui.State.ScreenMode = SCREEN_NORMAL
}
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}})
}
func (gui *Gui) setFiltering(path string) error {
gui.State.Modes.Filtering.SetPath(path)
if gui.State.ScreenMode == SCREEN_NORMAL {
gui.State.ScreenMode = SCREEN_HALF
}
if err := gui.c.PushContext(gui.State.Contexts.LocalCommits); err != nil {
return err
}
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() {
gui.State.Contexts.LocalCommits.SetSelectedLineIdx(0)
}})
}