1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-28 16:02:01 +03:00

support searching in side panels

For now we're just doing side panels, because it will take more work
to support this in the various main panel contexts
This commit is contained in:
Jesse Duffield
2020-02-23 21:53:30 +11:00
parent 2a5763a771
commit 46be280c92
18 changed files with 456 additions and 53 deletions

View File

@ -94,6 +94,12 @@ type Gui struct {
// tickingMutex ensures we don't have two loops ticking. The point of 'ticking'
// is to refresh the gui rapidly so that loader characters can be animated.
tickingMutex sync.Mutex
OnSearchEscape func() error
// these keys must either be of type Key of rune
SearchEscapeKey interface{}
NextSearchMatchKey interface{}
PrevSearchMatchKey interface{}
}
// NewGui returns a new Gui object with a given output mode.
@ -124,6 +130,11 @@ func NewGui(mode OutputMode, supportOverlaps bool) (*Gui, error) {
// view edges
g.SupportOverlaps = supportOverlaps
// default keys for when searching strings in a view
g.SearchEscapeKey = KeyEsc
g.NextSearchMatchKey = 'n'
g.PrevSearchMatchKey = 'N'
return g, nil
}
@ -803,6 +814,23 @@ func (g *Gui) execKeybindings(v *View, ev *termbox.Event) (matched bool, err err
var globalKb *keybinding
var matchingParentViewKb *keybinding
// if we're searching, and we've hit n/N/Esc, we ignore the default keybinding
if v.IsSearching() && Modifier(ev.Mod) == ModNone {
if eventMatchesKey(ev, g.NextSearchMatchKey) {
return true, v.gotoNextMatch()
} else if eventMatchesKey(ev, g.PrevSearchMatchKey) {
return true, v.gotoPreviousMatch()
} else if eventMatchesKey(ev, g.SearchEscapeKey) {
v.searcher.clearSearch()
if g.OnSearchEscape != nil {
if err := g.OnSearchEscape(); err != nil {
return true, err
}
}
return true, nil
}
}
for _, kb := range g.keybindings {
if kb.handler == nil {
continue