summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/gui/context')
-rw-r--r--pkg/gui/context/base_context.go62
-rw-r--r--pkg/gui/context/branches_context.go9
-rw-r--r--pkg/gui/context/commit_files_context.go9
-rw-r--r--pkg/gui/context/context.go189
-rw-r--r--pkg/gui/context/list_context_trait.go25
-rw-r--r--pkg/gui/context/local_commits_context.go9
-rw-r--r--pkg/gui/context/menu_context.go15
-rw-r--r--pkg/gui/context/patch_explorer_context.go134
-rw-r--r--pkg/gui/context/reflog_commits_context.go9
-rw-r--r--pkg/gui/context/remote_branches_context.go9
-rw-r--r--pkg/gui/context/remotes_context.go9
-rw-r--r--pkg/gui/context/simple_context.go41
-rw-r--r--pkg/gui/context/stash_context.go9
-rw-r--r--pkg/gui/context/sub_commits_context.go9
-rw-r--r--pkg/gui/context/submodules_context.go9
-rw-r--r--pkg/gui/context/suggestions_context.go9
-rw-r--r--pkg/gui/context/tags_context.go9
-rw-r--r--pkg/gui/context/view_trait.go8
-rw-r--r--pkg/gui/context/working_tree_context.go9
19 files changed, 374 insertions, 208 deletions
diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go
index 4e73aa0ff..58b8d25ab 100644
--- a/pkg/gui/context/base_context.go
+++ b/pkg/gui/context/base_context.go
@@ -8,7 +8,8 @@ import (
type BaseContext struct {
kind types.ContextKind
key types.ContextKey
- ViewName string
+ view *gocui.View
+ viewTrait types.IViewTrait
windowName string
onGetOptionsMap func() map[string]string
@@ -16,8 +17,9 @@ type BaseContext struct {
mouseKeybindingsFns []types.MouseKeybindingsFn
onClickFn func() error
- focusable bool
- transient bool
+ focusable bool
+ transient bool
+ hasControlledBounds bool
*ParentContextMgr
}
@@ -25,26 +27,33 @@ type BaseContext struct {
var _ types.IBaseContext = &BaseContext{}
type NewBaseContextOpts struct {
- Kind types.ContextKind
- Key types.ContextKey
- ViewName string
- WindowName string
- Focusable bool
- Transient bool
+ Kind types.ContextKind
+ Key types.ContextKey
+ View *gocui.View
+ WindowName string
+ Focusable bool
+ Transient bool
+ HasUncontrolledBounds bool // negating for the sake of making false the default
OnGetOptionsMap func() map[string]string
}
func NewBaseContext(opts NewBaseContextOpts) *BaseContext {
+ viewTrait := NewViewTrait(opts.View)
+
+ hasControlledBounds := !opts.HasUncontrolledBounds
+
return &BaseContext{
- kind: opts.Kind,
- key: opts.Key,
- ViewName: opts.ViewName,
- windowName: opts.WindowName,
- onGetOptionsMap: opts.OnGetOptionsMap,
- focusable: opts.Focusable,
- transient: opts.Transient,
- ParentContextMgr: &ParentContextMgr{},
+ kind: opts.Kind,
+ key: opts.Key,
+ view: opts.View,
+ windowName: opts.WindowName,
+ onGetOptionsMap: opts.OnGetOptionsMap,
+ focusable: opts.Focusable,
+ transient: opts.Transient,
+ hasControlledBounds: hasControlledBounds,
+ ParentContextMgr: &ParentContextMgr{},
+ viewTrait: viewTrait,
}
}
@@ -64,7 +73,20 @@ func (self *BaseContext) GetWindowName() string {
}
func (self *BaseContext) GetViewName() string {
- return self.ViewName
+ // for the sake of the global context which has no view
+ if self.view == nil {
+ return ""
+ }
+
+ return self.view.Name()
+}
+
+func (self *BaseContext) GetView() *gocui.View {
+ return self.view
+}
+
+func (self *BaseContext) GetViewTrait() types.IViewTrait {
+ return self.viewTrait
}
func (self *BaseContext) GetKind() types.ContextKind {
@@ -123,6 +145,10 @@ func (self *BaseContext) IsTransient() bool {
return self.transient
}
+func (self *BaseContext) HasControlledBounds() bool {
+ return self.hasControlledBounds
+}
+
func (self *BaseContext) Title() string {
return ""
}
diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go
index ba1982cbf..a3e404fdb 100644
--- a/pkg/gui/context/branches_context.go
+++ b/pkg/gui/context/branches_context.go
@@ -18,9 +18,9 @@ func NewBranchesContext(
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
- onFocus func(...types.OnFocusOpts) error,
- onRenderToMain func(...types.OnFocusOpts) error,
- onFocusLost func() error,
+ onFocus func(types.OnFocusOpts) error,
+ onRenderToMain func() error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
c *types.HelperCommon,
) *BranchesContext {
@@ -30,7 +30,7 @@ func NewBranchesContext(
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "branches",
+ View: view,
WindowName: "branches",
Key: LOCAL_BRANCHES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
@@ -41,7 +41,6 @@ func NewBranchesContext(
OnRenderToMain: onRenderToMain,
}),
list: viewModel,
- viewTrait: NewViewTrait(view),
getDisplayStrings: getDisplayStrings,
c: c,
},
diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go
index c95486cbf..4a28ac4c5 100644
--- a/pkg/gui/context/commit_files_context.go
+++ b/pkg/gui/context/commit_files_context.go
@@ -20,9 +20,9 @@ func NewCommitFilesContext(
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
- onFocus func(...types.OnFocusOpts) error,
- onRenderToMain func(...types.OnFocusOpts) error,
- onFocusLost func() error,
+ onFocus func(types.OnFocusOpts) error,
+ onRenderToMain func() error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
c *types.HelperCommon,
) *CommitFilesContext {
@@ -34,7 +34,7 @@ func NewCommitFilesContext(
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(
NewBaseContext(NewBaseContextOpts{
- ViewName: "commitFiles",
+ View: view,
WindowName: "commits",
Key: COMMIT_FILES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
@@ -47,7 +47,6 @@ func NewCommitFilesContext(
OnRenderToMain: onRenderToMain,
}),
list: viewModel,
- viewTrait: NewViewTrait(view),
getDisplayStrings: getDisplayStrings,
c: c,
},
diff --git a/pkg/gui/context/context.go b/pkg/gui/context/context.go
index c2001b215..a0925d2b8 100644
--- a/pkg/gui/context/context.go
+++ b/pkg/gui/context/context.go
@@ -1,39 +1,48 @@
package context
import (
- "sync"
-
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
const (
- GLOBAL_CONTEXT_KEY types.ContextKey = "global"
- STATUS_CONTEXT_KEY types.ContextKey = "status"
- FILES_CONTEXT_KEY types.ContextKey = "files"
- LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
- REMOTES_CONTEXT_KEY types.ContextKey = "remotes"
- REMOTE_BRANCHES_CONTEXT_KEY types.ContextKey = "remoteBranches"
- TAGS_CONTEXT_KEY types.ContextKey = "tags"
- LOCAL_COMMITS_CONTEXT_KEY types.ContextKey = "commits"
- REFLOG_COMMITS_CONTEXT_KEY types.ContextKey = "reflogCommits"
- SUB_COMMITS_CONTEXT_KEY types.ContextKey = "subCommits"
- COMMIT_FILES_CONTEXT_KEY types.ContextKey = "commitFiles"
- STASH_CONTEXT_KEY types.ContextKey = "stash"
- MAIN_NORMAL_CONTEXT_KEY types.ContextKey = "normal"
- MAIN_MERGING_CONTEXT_KEY types.ContextKey = "merging"
- MAIN_PATCH_BUILDING_CONTEXT_KEY types.ContextKey = "patchBuilding"
- MAIN_STAGING_CONTEXT_KEY types.ContextKey = "staging"
- MENU_CONTEXT_KEY types.ContextKey = "menu"
- CONFIRMATION_CONTEXT_KEY types.ContextKey = "confirmation"
- SEARCH_CONTEXT_KEY types.ContextKey = "search"
- COMMIT_MESSAGE_CONTEXT_KEY types.ContextKey = "commitMessage"
- SUBMODULES_CONTEXT_KEY types.ContextKey = "submodules"
- SUGGESTIONS_CONTEXT_KEY types.ContextKey = "suggestions"
- COMMAND_LOG_CONTEXT_KEY types.ContextKey = "cmdLog"
+ GLOBAL_CONTEXT_KEY types.ContextKey = "global"
+ STATUS_CONTEXT_KEY types.ContextKey = "status"
+ FILES_CONTEXT_KEY types.ContextKey = "files"
+ LOCAL_BRANCHES_CONTEXT_KEY types.ContextKey = "localBranches"
+ REMOTES_CONTEXT_KEY types.ContextKey = "remotes"
+ REMOTE_BRANCHES_CONTEXT_KEY types.ContextKey = "remoteBranches"
+ TAGS_CONTEXT_KEY types.ContextKey = "tags"
+ LOCAL_COMMITS_CONTEXT_KEY types.ContextKey = "commits"
+ REFLOG_COMMITS_CONTEXT_KEY types.ContextKey = "reflogCommits"
+ SUB_COMMITS_CONTEXT_KEY types.ContextKey = "subCommits"
+ COMMIT_FILES_CONTEXT_KEY types.ContextKey = "commitFiles"
+ STASH_CONTEXT_KEY types.ContextKey = "stash"
+ NORMAL_MAIN_CONTEXT_KEY types.ContextKey = "normal"
+ NORMAL_SECONDARY_CONTEXT_KEY types.ContextKey = "normalSecondary"
+ STAGING_MAIN_CONTEXT_KEY types.ContextKey = "staging"
+ STAGING_SECONDARY_CONTEXT_KEY types.ContextKey = "stagingSecondary"
+ PATCH_BUILDING_MAIN_CONTEXT_KEY types.ContextKey = "patchBuilding"
+ PATCH_BUILDING_SECONDARY_CONTEXT_KEY types.ContextKey = "patchBuildingSecondary"
+ MERGING_MAIN_CONTEXT_KEY types.ContextKey = "merging"
+
+ // these shouldn't really be needed for anything but I'm giving them unique keys nonetheless
+ OPTIONS_CONTEXT_KEY types.ContextKey = "options"
+ APP_STATUS_CONTEXT_KEY types.ContextKey = "appStatus"
+ SEARCH_PREFIX_CONTEXT_KEY types.ContextKey = "searchPrefix"
+ INFORMATION_CONTEXT_KEY types.ContextKey = "information"
+ LIMIT_CONTEXT_KEY types.ContextKey = "limit"
+
+ MENU_CONTEXT_KEY types.ContextKey = "menu"
+ CONFIRMATION_CONTEXT_KEY types.ContextKey = "confirmation"
+ SEARCH_CONTEXT_KEY types.ContextKey = "search"
+ COMMIT_MESSAGE_CONTEXT_KEY types.ContextKey = "commitMessage"
+ SUBMODULES_CONTEXT_KEY types.ContextKey = "submodules"
+ SUGGESTIONS_CONTEXT_KEY types.ContextKey = "suggestions"
+ COMMAND_LOG_CONTEXT_KEY types.ContextKey = "cmdLog"
)
var AllContextKeys = []types.ContextKey{
- GLOBAL_CONTEXT_KEY, // not focusable
+ GLOBAL_CONTEXT_KEY,
STATUS_CONTEXT_KEY,
FILES_CONTEXT_KEY,
LOCAL_BRANCHES_CONTEXT_KEY,
@@ -45,10 +54,14 @@ var AllContextKeys = []types.ContextKey{
SUB_COMMITS_CONTEXT_KEY,
COMMIT_FILES_CONTEXT_KEY,
STASH_CONTEXT_KEY,
- MAIN_NORMAL_CONTEXT_KEY, // not focusable
- MAIN_MERGING_CONTEXT_KEY,
- MAIN_PATCH_BUILDING_CONTEXT_KEY,
- MAIN_STAGING_CONTEXT_KEY, // not focusable for secondary view
+ NORMAL_MAIN_CONTEXT_KEY,
+ NORMAL_SECONDARY_CONTEXT_KEY,
+ STAGING_MAIN_CONTEXT_KEY,
+ STAGING_SECONDARY_CONTEXT_KEY,
+ PATCH_BUILDING_MAIN_CONTEXT_KEY,
+ PATCH_BUILDING_SECONDARY_CONTEXT_KEY,
+ MERGING_MAIN_CONTEXT_KEY,
+
MENU_CONTEXT_KEY,
CONFIRMATION_CONTEXT_KEY,
SEARCH_CONTEXT_KEY,
@@ -59,87 +72,81 @@ var AllContextKeys = []types.ContextKey{
}
type ContextTree struct {
- Global types.Context
- Status types.Context
- Files *WorkingTreeContext
- Menu *MenuContext
- Branches *BranchesContext
- Tags *TagsContext
- LocalCommits *LocalCommitsContext
- CommitFiles *CommitFilesContext
- Remotes *RemotesContext
- Submodules *SubmodulesContext
- RemoteBranches *RemoteBranchesContext
- ReflogCommits *ReflogCommitsContext
- SubCommits *SubCommitsContext
- Stash *StashContext
- Suggestions *SuggestionsContext
- Normal types.Context
- Staging types.Context
- PatchBuilding types.Context
- Merging types.Context
- Confirmation types.Context
- CommitMessage types.Context
- Search types.Context
- CommandLog types.Context
+ Global types.Context
+ Status types.Context
+ Files *WorkingTreeContext
+ Menu *MenuContext
+ Branches *BranchesContext
+ Tags *TagsContext
+ LocalCommits *LocalCommitsContext
+ CommitFiles *CommitFilesContext
+ Remotes *RemotesContext
+ Submodules *SubmodulesContext
+ RemoteBranches *RemoteBranchesContext
+ ReflogCommits *ReflogCommitsContext
+ SubCommits *SubCommitsContext
+ Stash *StashContext
+ Suggestions *SuggestionsContext
+ Normal types.Context
+ NormalSecondary types.Context
+ Staging *PatchExplorerContext
+ StagingSecondary *PatchExplorerContext
+ CustomPatchBuilder *PatchExplorerContext
+ CustomPatchBuilderSecondary types.Context
+ Merging types.Context
+ Confirmation types.Context
+ CommitMessage types.Context
+ CommandLog types.Context
+
+ // display contexts
+ AppStatus types.Context
+ Options types.Context
+ SearchPrefix types.Context
+ Search types.Context
+ Information types.Context
+ Limit types.Context
}
+// the order of this decides which context is initially at the top of its window
func (self *ContextTree) Flatten() []types.Context {
return []types.Context{
self.Global,
self.Status,
- self.Files,
self.Submodules,
- self.Branches,
+ self.Files,
+ self.SubCommits,
self.Remotes,
self.RemoteBranches,
self.Tags,
- self.LocalCommits,
+ self.Branches,
self.CommitFiles,
self.ReflogCommits,
+ self.LocalCommits,
self.Stash,
self.Menu,
self.Confirmation,
self.CommitMessage,
- self.Normal,
- self.Staging,
+
self.Merging,
- self.PatchBuilding,
- self.SubCommits,
+ self.StagingSecondary,
+ self.Staging,
+ self.CustomPatchBuilderSecondary,
+ self.CustomPatchBuilder,
+ self.NormalSecondary,
+ self.Normal,
+
self.Suggestions,
self.CommandLog,
+ self.AppStatus,
+ self.Options,
+ self.SearchPrefix,
+ self.Search,
+ self.Information,
+ self.Limit,
}
}
-type ViewContextMap struct {
- content map[string]types.Context
- sync.RWMutex
-}
-
-func NewViewContextMap() *ViewContextMap {
- return &ViewContextMap{content: map[string]types.Context{}}
-}
-
-func (self *ViewContextMap) Get(viewName string) types.Context {
- self.RLock()
- defer self.RUnlock()
-
- return self.content[viewName]
-}
-
-func (self *ViewContextMap) Set(viewName string, context types.Context) {
- self.Lock()
- defer self.Unlock()
- self.content[viewName] = context
-}
-
-func (self *ViewContextMap) Entries() map[string]types.Context {
- self.Lock()
- defer self.Unlock()
- return self.content
-}
-
-type TabContext struct {
- Tab string
- Context types.Context
+type TabView struct {
+ Tab string
+ ViewName string
}
diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go
index 04cbefcf9..df5bbc0af 100644
--- a/pkg/gui/context/list_context_trait.go
+++ b/pkg/gui/context/list_context_trait.go
@@ -12,7 +12,6 @@ type ListContextTrait struct {
c *types.HelperCommon
list types.IList
- viewTrait *ViewTrait
getDisplayStrings func(startIdx int, length int) [][]string
}
@@ -20,43 +19,39 @@ func (self *ListContextTrait) GetList() types.IList {
return self.list
}
-func (self *ListContextTrait) GetViewTrait() types.IViewTrait {
- return self.viewTrait
-}
-
func (self *ListContextTrait) FocusLine() {
// we need a way of knowing whether we've rendered to the view yet.
- self.viewTrait.FocusPoint(self.list.GetSelectedLineIdx())
+ self.GetViewTrait().FocusPoint(self.list.GetSelectedLineIdx())
self.setFooter()
}
func (self *ListContextTrait) setFooter() {
- self.viewTrait.SetFooter(formatListFooter(self.list.GetSelectedLineIdx(), self.list.Len()))
+ self.GetViewTrait().SetFooter(formatListFooter(self.list.GetSelectedLineIdx(), self.list.Len()))
}
func formatListFooter(selectedLineIdx int, length int) string {
return fmt.Sprintf("%d of %d", selectedLineIdx+1, length)
}
-func (self *ListContextTrait) HandleFocus(opts ...types.OnFocusOpts) error {
+func (self *ListContextTrait) HandleFocus(opts types.OnFocusOpts) error {
self.FocusLine()
- self.viewTrait.SetHighlight(self.list.Len() > 0)
+ self.GetViewTrait().SetHighlight(self.list.Len() > 0)
- return self.Context.HandleFocus(opts...)
+ return self.Context.HandleFocus(opts)
}
-func (self *ListContextTrait) HandleFocusLost() error {
- self.viewTrait.SetOriginX(0)
+func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) error {
+ self.GetViewTrait().SetOriginX(0)
- return self.Context.HandleFocusLost()
+ return self.Context.HandleFocusLost(opts)
}
// OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view
func (self *ListContextTrait) HandleRender() error {
self.list.RefreshSelectedIdx()
content := utils.RenderDisplayStrings(self.getDisplayStrings(0, self.list.Len()))
- self.viewTrait.SetContent(content)
+ self.GetViewTrait().SetContent(content)
self.c.Render()
self.setFooter()
@@ -65,5 +60,5 @@ func (self *ListContextTrait) HandleRender() error {
func (self *ListContextTrait) OnSearchSelect(selectedLineIdx int) error {
self.GetList().SetSelectedLineIdx(selectedLineIdx)
- return self.HandleFocus()
+ return self.HandleFocus(types.OnFocusOpts{})
}
diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go
index 9550bcfdb..462a85d59 100644
--- a/pkg/gui/context/local_commits_context.go
+++ b/pkg/gui/context/local_commits_context.go
@@ -18,9 +18,9 @@ func NewLocalCommitsContext(
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
- onFocus func(...types.OnFocusOpts) error,
- onRenderToMain func(...types.OnFocusOpts) error,
- onFocusLost func() error,
+ onFocus func(types.OnFocusOpts) error,
+ onRenderToMain func() error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
c *types.HelperCommon,
) *LocalCommitsContext {
@@ -31,7 +31,7 @@ func NewLocalCommitsContext(
ViewportListContextTrait: &ViewportListContextTrait{
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "commits",
+ View: view,
WindowName: "commits",
Key: LOCAL_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
@@ -42,7 +42,6 @@ func NewLocalCommitsContext(
OnRenderToMain: onRenderToMain,
}),
list: viewModel,
- viewTrait: NewViewTrait(view),
getDisplayStrings: getDisplayStrings,
c: c,
},
diff --git a/pkg/gui/context/menu_context.go b/pkg/gui/context/menu_context.go
index f71feaeae..7754d02ae 100644
--- a/pkg/gui/context/menu_context.go
+++ b/pkg/gui/context/menu_context.go
@@ -24,7 +24,7 @@ func NewMenuContext(
) *MenuContext {
viewModel := NewMenuViewModel()
- onFocus := func(...types.OnFocusOpts) error {
+ onFocus := func(types.OnFocusOpts) error {
selectedMenuItem := viewModel.GetSelected()
renderToDescriptionView(selectedMenuItem.Tooltip)
return nil
@@ -34,17 +34,18 @@ func NewMenuContext(
MenuViewModel: viewModel,
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "menu",
- Key: "menu",
- Kind: types.TEMPORARY_POPUP,
- OnGetOptionsMap: getOptionsMap,
- Focusable: true,
+ View: view,
+ WindowName: "menu",
+ Key: "menu",
+ Kind: types.TEMPORARY_POPUP,
+ OnGetOptionsMap: getOptionsMap,
+ Focusable: true,
+ HasUncontrolledBounds: true,
}), ContextCallbackOpts{
OnFocus: onFocus,
}),
getDisplayStrings: viewModel.GetDisplayStrings,
list: viewModel,
- viewTrait: NewViewTrait(view),
c: c,
},
}
diff --git a/pkg/gui/context/patch_explorer_context.go b/pkg/gui/context/patch_explorer_context.go
new file mode 100644
index 000000000..626c0be84
--- /dev/null
+++ b/pkg/gui/context/patch_explorer_context.go
@@ -0,0 +1,134 @@
+package context
+
+import (
+ "sync"
+
+ "github.com/jesseduffield/gocui"
+ "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring"
+ "github.com/jesseduffield/lazygit/pkg/gui/types"
+)
+
+type PatchExplorerContext struct {
+ *SimpleContext
+
+ state *patch_exploring.State
+ viewTrait *ViewTrait
+ getIncludedLineIndices func() []int
+ c *types.HelperCommon
+ mutex *sync.Mutex
+}
+
+var _ types.IPatchExplorerContext = (*PatchExplorerContext)(nil)
+
+func NewPatchExplorerContext(
+ view *gocui.View,
+ windowName string,
+ key types.ContextKey,
+
+ onFocus func(types.OnFocusOpts) error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
+ getIncludedLineIndices func() []int,
+
+ c *types.HelperCommon,
+) *PatchExplorerContext {
+ return &PatchExplorerContext{
+ state: nil,
+ viewTrait: NewViewTrait(view),
+ c: c,
+ mutex: &sync.Mutex{},
+ getIncludedLineIndices: getIncludedLineIndices,
+ SimpleContext: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
+ View: view,
+ WindowName: windowName,
+ Key: key,
+ Kind: types.MAIN_CONTEXT,
+ Focusable: true,
+ }), ContextCallbackOpts{
+ OnFocus: onFocus,
+ OnFocusLost: onFocusLost,
+ }),
+ }
+}
+
+func (self *PatchExplorerContext) GetState() *patch_exploring.State {
+ return self.state
+}
+
+func (self *PatchExplorerContext) SetState(state *patch_exploring.State) {
+ self.state = state
+}
+
+func (self *PatchExplorerContext) GetViewTrait() types.IViewTrait {
+ return self.viewTrait
+}
+
+func (self *PatchExplorerContext) GetIncludedLineIndices() []int {
+ return self.getIncludedLineIndices()
+}
+
+func (self *PatchExplorerContext) RenderAndFocus(isFocused bool) error {
+ self.GetView().SetContent(self.GetContentToRender(isFocused))
+
+ if err := self.focusSelection(); err != nil {
+ return err
+ }
+
+ self.c.Render()
+
+ return nil
+}
+
+func (self *PatchExplorerContext) Render(isFocused bool) error {
+ self.GetView().SetContent(self.GetContentToRender(isFocused))
+
+ self.c.Render()
+
+ return nil
+}
+
+func (self *PatchExplorerContext) Focus() error {
+ if err := self.focusSelection(); err != nil {
+ return err
+ }
+
+ self.c.Render()
+
+ return nil
+}
+
+func (self *PatchExplorerContext) focusSelection() error {
+ view := self.GetView()
+ state := self.GetState()
+ _, viewHeight := view.Size()
+ bufferHeight := viewHeight - 1
+ _, origin := view.Origin()
+
+ selectedLineIdx := state.GetSelectedLineIdx()
+
+ newOrigin := state.CalculateOrigin(origin, bufferHeight)
+
+ if err := view.SetOriginY(newOrigin); err != nil {
+ return err
+ }
+
+ return view.SetCursor(0, selectedLineIdx-newOrigin)
+}
+
+func (self *PatchExplorerContext) GetContentToRender(isFocused bool) string {
+ if self.GetState() == nil {
+ return ""
+ }
+
+ return self.GetState().RenderForLineIndices(isFocused, self.GetIncludedLineIndices())
+}
+
+func (self *PatchExplorerContext) NavigateTo(isFocused bool, selectedLineIdx int) error {
+ self.GetState().SetLineSelectMode()
+ self.GetState().SelectLine(selectedLineIdx)
+
+ return self.RenderAndFocus(isFocused)
+}
+
+func (self *PatchExplorerContext) GetMutex() *sync.Mutex {
+ return self.mutex
+}
diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go
index 1062009e9..e197a50bd 100644
--- a/pkg/gui/context/reflog_commits_context.go
+++ b/pkg/gui/context/reflog_commits_context.go
@@ -18,9 +18,9 @@ func NewReflogCommitsContext(
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
- onFocus func(...types.OnFocusOpts) error,
- onRenderToMain func(...types.OnFocusOpts) error,
- onFocusLost func() error,
+ onFocus func(types.OnFocusOpts) error,
+ onRenderToMain func() error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
c *types.HelperCommon,
) *ReflogCommitsContext {
@@ -30,7 +30,7 @@ func NewReflogCommitsContext(
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "commits",
+ View: view,
WindowName: "commits",
Key: REFLOG_COMMITS_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
@@ -41,7 +41,6 @@ func NewReflogCommitsContext(
OnRenderToMain: onRenderToMain,
}),
list: viewModel,
- viewTrait: NewViewTrait(view),
getDisplayStrings: getDisplayStrings,
c: c,
},
diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go
index d8e9a91bf..44dc06848 100644
--- a/pkg/gui/context/remote_branches_context.go
+++ b/pkg/gui/context/remote_branches_context.go
@@ -19,9 +19,9 @@ func NewRemoteBranchesContext(
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
- onFocus func(...types.OnFocusOpts) error,
- onRenderToMain func(...types.OnFocusOpts) error,
- onFocusLost func() error,
+ onFocus func(types.OnFocusOpts) error,
+ onRenderToMain func() error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
c *types.HelperCommon,
) *RemoteBranchesContext {
@@ -32,7 +32,7 @@ func NewRemoteBranchesContext(
DynamicTitleBuilder: NewDynamicTitleBuilder(c.Tr.RemoteBranchesDynamicTitle),
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "remoteBranches",
+ View: view,
WindowName: "branches",
Key: REMOTE_BRANCHES_CONTEXT_KEY,
Kind: types.SIDE_CONTEXT,
@@ -44,7 +44,6 @@ func NewRemoteBranchesContext(
OnRenderToMain: onRenderToMain,
}),
list: viewModel,
- viewTrait: NewViewTrait(view),
getDisplayStrings: getDisplayStrings,
c: c,
},
diff --git a/pkg/gui/context/remotes_context.go b/pkg/gui/context/remotes_context.go
index 9cb0b6054..0f11908dd 100644
--- a/pkg/gui/context/remotes_context.go
+++ b/pkg/gui/context/remotes_context.go
@@ -18,9 +18,9 @@ func NewRemotesContext(
view *gocui.View,
getDisplayStrings func(startIdx int, length int) [][]string,
- onFocus func(...types.OnFocusOpts) error,
- onRenderToMain func(...types.OnFocusOpts) error,
- onFocusLost func() error,
+ onFocus func(types.OnFocusOpts) error,
+ onRenderToMain func() error,
+ onFocusLost func(opts types.OnFocusLostOpts) error,
c *types.HelperCommon,
) *RemotesContext {
@@ -30,7 +30,7 @@ func NewRemotesContext(
BasicViewModel: viewModel,
ListContextTrait: &ListContextTrait{
Context: NewSimpleContext(NewBaseContext(NewBaseContextOpts{
- ViewName: "branches",
+ View: view,
WindowName: "branches",
Key: REMOTES_CONTEXT_KEY,