1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-23 22:24:51 +02:00

Make the main view searchable

This commit is contained in:
Stefan Haller
2025-03-25 14:33:24 +01:00
parent 2b399a3c36
commit ec51efc82c
12 changed files with 34 additions and 2 deletions

View File

@@ -7,12 +7,16 @@ import (
type MainContext struct {
*SimpleContext
*SearchTrait
}
var _ types.ISearchableContext = (*MainContext)(nil)
func NewMainContext(
view *gocui.View,
windowName string,
key types.ContextKey,
c *ContextCommon,
) *MainContext {
ctx := &MainContext{
SimpleContext: NewSimpleContext(
@@ -24,7 +28,14 @@ func NewMainContext(
Focusable: true,
HighlightOnFocus: false,
})),
SearchTrait: NewSearchTrait(c),
}
ctx.GetView().SetOnSelectItem(ctx.SearchTrait.onSelectItemWrapper(func(int) error { return nil }))
return ctx
}
func (self *MainContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
return nil
}

View File

@@ -39,8 +39,8 @@ func NewContextTree(c *ContextCommon) *ContextTree {
Tags: NewTagsContext(c),
Stash: NewStashContext(c),
Suggestions: NewSuggestionsContext(c),
Normal: NewMainContext(c.Views().Main, "main", NORMAL_MAIN_CONTEXT_KEY),
NormalSecondary: NewMainContext(c.Views().Secondary, "secondary", NORMAL_SECONDARY_CONTEXT_KEY),
Normal: NewMainContext(c.Views().Main, "main", NORMAL_MAIN_CONTEXT_KEY, c),
NormalSecondary: NewMainContext(c.Views().Secondary, "secondary", NORMAL_SECONDARY_CONTEXT_KEY, c),
Staging: NewPatchExplorerContext(
c.Views().Staging,
"main",

View File

@@ -44,6 +44,9 @@ func (self *SwitchToFocusedMainViewController) Context() types.Context {
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
mainViewContext := self.c.Helpers().Window.GetContextForWindow("main")
mainViewContext.SetParentContext(self.context)
if context, ok := mainViewContext.(types.ISearchableContext); ok {
context.ClearSearchString()
}
self.c.Context().Push(mainViewContext, types.OnFocusOpts{})
return nil
}