From cbd23107efb21e521e13d4915b9c4dcb93a414a1 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 15 Oct 2024 16:59:50 +0200 Subject: [PATCH] WIP Make it searchable Doesn't work very well yet, but it gives you a taste of what it could look like. --- pkg/gui/context/diff_context.go | 53 +++++++++++++++++++++++++++++++++ pkg/gui/context/setup.go | 22 ++------------ 2 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 pkg/gui/context/diff_context.go diff --git a/pkg/gui/context/diff_context.go b/pkg/gui/context/diff_context.go new file mode 100644 index 000000000..3763fedc2 --- /dev/null +++ b/pkg/gui/context/diff_context.go @@ -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 +} diff --git a/pkg/gui/context/setup.go b/pkg/gui/context/setup.go index 11b0e0006..b46e5b8f4 100644 --- a/pkg/gui/context/setup.go +++ b/pkg/gui/context/setup.go @@ -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",