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

57 lines
1.3 KiB
Go
Raw Normal View History

2020-03-29 01:31:34 +02:00
package gui
2022-01-28 11:44:36 +02:00
import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
func (gui *Gui) validateNotInFilterMode() bool {
if gui.State.Modes.Filtering.Active() {
_ = gui.c.Confirm(types.ConfirmOpts{
Title: gui.c.Tr.MustExitFilterModeTitle,
Prompt: gui.c.Tr.MustExitFilterModePrompt,
2022-01-28 11:44:36 +02:00
HandleConfirm: gui.exitFilterMode,
2020-08-15 08:36:39 +02:00
})
return false
}
return true
}
func (gui *Gui) outsideFilterMode(f func() error) func() error {
return func() error {
if !gui.validateNotInFilterMode() {
return nil
}
return f()
2020-03-29 01:31:34 +02:00
}
}
func (gui *Gui) exitFilterMode() error {
2021-04-03 02:32:14 +02:00
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}})
2021-04-03 02:32:14 +02:00
}
func (gui *Gui) setFiltering(path string) error {
gui.State.Modes.Filtering.SetPath(path)
if gui.State.ScreenMode == SCREEN_NORMAL {
gui.State.ScreenMode = SCREEN_HALF
}
2022-02-13 08:01:53 +02:00
if err := gui.c.PushContext(gui.State.Contexts.LocalCommits); err != nil {
2021-04-03 02:32:14 +02:00
return err
}
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.COMMITS}, Then: func() {
2022-02-13 08:01:53 +02:00
gui.State.Contexts.LocalCommits.SetSelectedLineIdx(0)
2021-04-03 02:32:14 +02:00
}})
2020-03-29 01:31:34 +02:00
}