WIP Make it searchable

Doesn't work very well yet, but it gives you a taste of what it could look like.
This commit is contained in:
Stefan Haller 2024-10-15 16:59:50 +02:00
parent 50426cda3a
commit cbd23107ef
2 changed files with 55 additions and 20 deletions

View File

@ -0,0 +1,53 @@
package context
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
type DiffContext struct {
*SimpleContext
*SearchTrait
c *ContextCommon
}
var _ types.ISearchableContext = (*DiffContext)(nil)
func NewDiffContext(
view *gocui.View,
windowName string,
key types.ContextKey,
c *ContextCommon,
) *DiffContext {
ctx := &DiffContext{
SimpleContext: NewSimpleContext(
NewBaseContext(NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
View: view,
WindowName: windowName,
Key: key,
Focusable: true,
HighlightOnFocus: true,
})),
SearchTrait: NewSearchTrait(c),
c: c,
}
// TODO: copied from PatchExplorerContext. Do we need something like this?
// ctx.GetView().SetOnSelectItem(ctx.SearchTrait.onSelectItemWrapper(
// func(selectedLineIdx int) error {
// ctx.GetMutex().Lock()
// defer ctx.GetMutex().Unlock()
// ctx.NavigateTo(ctx.c.Context().IsCurrent(ctx), selectedLineIdx)
// return nil
// }),
// )
return ctx
}
func (self *DiffContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
return nil
}

View File

@ -57,26 +57,8 @@ func NewContextTree(c *ContextCommon) *ContextTree {
Focusable: false,
}),
),
Diff: NewSimpleContext(
NewBaseContext(NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
View: c.Views().Diff,
WindowName: "main",
Key: DIFF_MAIN_CONTEXT_KEY,
Focusable: true,
HighlightOnFocus: true,
}),
),
DiffSecondary: NewSimpleContext(
NewBaseContext(NewBaseContextOpts{
Kind: types.MAIN_CONTEXT,
View: c.Views().DiffSecondary,
WindowName: "secondary",
Key: DIFF_SECONDARY_CONTEXT_KEY,
Focusable: true,
HighlightOnFocus: true,
}),
),
Diff: NewDiffContext(c.Views().Diff, "main", DIFF_MAIN_CONTEXT_KEY, c),
DiffSecondary: NewDiffContext(c.Views().DiffSecondary, "secondary", DIFF_SECONDARY_CONTEXT_KEY, c),
Staging: NewPatchExplorerContext(
c.Views().Staging,
"main",