diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index 51d2473c3..b5fbf76ce 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -28,7 +28,7 @@ type BaseContext struct { hasControlledBounds bool needsRerenderOnWidthChange types.NeedsRerenderOnWidthChangeLevel needsRerenderOnHeightChange bool - highlightOnFocus bool + hasSelectableContent bool *ParentContextMgr } @@ -49,7 +49,7 @@ type NewBaseContextOpts struct { Focusable bool Transient bool HasUncontrolledBounds bool // negating for the sake of making false the default - HighlightOnFocus bool + HasSelectableContent bool NeedsRerenderOnWidthChange types.NeedsRerenderOnWidthChangeLevel NeedsRerenderOnHeightChange bool @@ -70,7 +70,7 @@ func NewBaseContext(opts NewBaseContextOpts) *BaseContext { focusable: opts.Focusable, transient: opts.Transient, hasControlledBounds: hasControlledBounds, - highlightOnFocus: opts.HighlightOnFocus, + hasSelectableContent: opts.HasSelectableContent, needsRerenderOnWidthChange: opts.NeedsRerenderOnWidthChange, needsRerenderOnHeightChange: opts.NeedsRerenderOnHeightChange, ParentContextMgr: &ParentContextMgr{}, @@ -118,6 +118,10 @@ func (self *BaseContext) GetKind() types.ContextKind { return self.kind } +func (self *BaseContext) HasSelectableContent() bool { + return self.hasSelectableContent +} + func (self *BaseContext) GetKey() types.ContextKey { return self.key } diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index 77e071991..102684e58 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -37,6 +37,10 @@ type ListContextTrait struct { func (self *ListContextTrait) IsListContext() {} +func (self *ListContextTrait) HasSelectableContent() bool { + return self.list.Len() > 0 +} + func (self *ListContextTrait) FocusLine(scrollIntoView bool) { self.Context.FocusLine(scrollIntoView) @@ -102,7 +106,7 @@ func formatListFooter(selectedLineIdx int, length int) string { func (self *ListContextTrait) HandleFocus(opts types.OnFocusOpts) { self.FocusLine(!opts.KeepScrollPosition) - self.GetViewTrait().SetHighlight(self.list.Len() > 0) + self.GetViewTrait().SetHighlight(self.HasSelectableContent()) self.Context.HandleFocus(opts) } diff --git a/pkg/gui/context/main_context.go b/pkg/gui/context/main_context.go index c8b6edade..692c6dd5c 100644 --- a/pkg/gui/context/main_context.go +++ b/pkg/gui/context/main_context.go @@ -21,12 +21,12 @@ func NewMainContext( ctx := &MainContext{ SimpleContext: NewSimpleContext( NewBaseContext(NewBaseContextOpts{ - Kind: types.MAIN_CONTEXT, - View: view, - WindowName: windowName, - Key: key, - Focusable: true, - HighlightOnFocus: false, + Kind: types.MAIN_CONTEXT, + View: view, + WindowName: windowName, + Key: key, + Focusable: true, + HasSelectableContent: false, })), SearchTrait: NewSearchTrait(c), } diff --git a/pkg/gui/context/merge_conflicts_context.go b/pkg/gui/context/merge_conflicts_context.go index 2ab446c06..dd1060288 100644 --- a/pkg/gui/context/merge_conflicts_context.go +++ b/pkg/gui/context/merge_conflicts_context.go @@ -35,12 +35,12 @@ func NewMergeConflictsContext( viewModel: viewModel, Context: NewSimpleContext( NewBaseContext(NewBaseContextOpts{ - Kind: types.MAIN_CONTEXT, - View: c.Views().MergeConflicts, - WindowName: "main", - Key: MERGE_CONFLICTS_CONTEXT_KEY, - Focusable: true, - HighlightOnFocus: true, + Kind: types.MAIN_CONTEXT, + View: c.Views().MergeConflicts, + WindowName: "main", + Key: MERGE_CONFLICTS_CONTEXT_KEY, + Focusable: true, + HasSelectableContent: true, }), ), c: c, diff --git a/pkg/gui/context/patch_explorer_context.go b/pkg/gui/context/patch_explorer_context.go index 334c2e374..434de6e58 100644 --- a/pkg/gui/context/patch_explorer_context.go +++ b/pkg/gui/context/patch_explorer_context.go @@ -47,7 +47,7 @@ func NewPatchExplorerContext( Key: key, Kind: types.MAIN_CONTEXT, Focusable: true, - HighlightOnFocus: true, + HasSelectableContent: true, NeedsRerenderOnWidthChange: types.NEEDS_RERENDER_ON_WIDTH_CHANGE_WHEN_WIDTH_CHANGES, })), SearchTrait: NewSearchTrait(c), diff --git a/pkg/gui/context/simple_context.go b/pkg/gui/context/simple_context.go index 626d5dfcf..36cd90d96 100644 --- a/pkg/gui/context/simple_context.go +++ b/pkg/gui/context/simple_context.go @@ -33,7 +33,7 @@ func NewDisplayContext(key types.ContextKey, view *gocui.View, windowName string } func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) { - if self.highlightOnFocus { + if self.hasSelectableContent { self.GetViewTrait().SetHighlight(true) } diff --git a/pkg/gui/types/context.go b/pkg/gui/types/context.go index 2ef798a34..ddf7b345c 100644 --- a/pkg/gui/types/context.go +++ b/pkg/gui/types/context.go @@ -75,6 +75,10 @@ type IBaseContext interface { // determined independently. HasControlledBounds() bool + // true if the context holds something for a selection to sit on. Contexts that + // don't show a selection at all say false, and so do lists with nothing in them. + HasSelectableContent() bool + // the total height of the content that the view is currently showing TotalContentHeight() int