Skip to content

Commit 1c107fd

Browse files
committed
Fix view selection running out of sync with list selection when view isn't focused
When rerendering a view at the end of a refresh, we call HandleFocus only if the view has the focus. This is so that we rerender the main view for the new selection. What was missing here is to update the view selection from the list selection if the view doesn't have the focus, so that the selection is painted properly. Normally this is not relevant because you don't see the selection if another side panel has the focus; however, you do see it as an inactive selection when e.g. a popup is shown, in which case it does matter. This will become more important when we introduce section headers for commits, because in that case the view selection needs to change when the working copy state changes from normal to rebasing or vice versa, even if the list selection stays the same. The changed test submodule/reset.go shows how this was wrong before: when entering the submodule again after resetting, there is a refresh which keeps the same branch selected as before (master); however, since the branches panel is not focused, the view didn't notice and kept thinking that the detached head is selected (which it isn't, you can tell by running the test in sandbox mode and focusing the branches panel at the end: you'll see that master is selected). So the change in this commit fixes that.
1 parent 9a5e245 commit 1c107fd

File tree

5 files changed

+15
-3
lines changed

5 files changed

+15
-3
lines changed

Diff for: pkg/gui/context/list_context_trait.go

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type ListContextTrait struct {
2626
func (self *ListContextTrait) IsListContext() {}
2727

2828
func (self *ListContextTrait) FocusLine() {
29+
self.Context.FocusLine()
30+
2931
// Doing this at the end of the layout function because we need the view to be
3032
// resized before we focus the line, otherwise if we're in accordion mode
3133
// the view could be squashed and won't how to adjust the cursor/origin.

Diff for: pkg/gui/context/simple_context.go

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
5454
}
5555
}
5656

57+
func (self *SimpleContext) FocusLine() {
58+
}
59+
5760
func (self *SimpleContext) HandleRender() {
5861
if self.handleRenderFunc != nil {
5962
self.handleRenderFunc()

Diff for: pkg/gui/types/context.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type Context interface {
105105

106106
HandleFocus(opts OnFocusOpts)
107107
HandleFocusLost(opts OnFocusLostOpts)
108+
FocusLine()
108109
HandleRender()
109110
HandleRenderToMain()
110111
}
@@ -173,7 +174,6 @@ type IListContext interface {
173174
ViewIndexToModelIndex(int) int
174175
ModelIndexToViewIndex(int) int
175176

176-
FocusLine()
177177
IsListContext() // used for type switch
178178
RangeSelectEnabled() bool
179179
RenderOnlyVisibleLines() bool

Diff for: pkg/gui/view_helpers.go

+7
Original file line numberDiff line numberDiff line change
@@ -136,5 +136,12 @@ func (gui *Gui) postRefreshUpdate(c types.Context) {
136136

137137
if gui.currentViewName() == c.GetViewName() {
138138
c.HandleFocus(types.OnFocusOpts{})
139+
} else {
140+
// The FocusLine call is included in the HandleFocus method which we
141+
// call for focused views above; but we need to call it here for
142+
// non-focused views to ensure that an inactive selection is painted
143+
// correctly, and that integration tests see the up to date selection
144+
// state.
145+
c.FocusLine()
139146
}
140147
}

Diff for: pkg/integration/tests/submodule/reset.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ var Reset = NewIntegrationTest(NewIntegrationTestArgs{
107107

108108
// submodule has been hard reset to the commit the parent repo specifies
109109
t.Views().Branches().Lines(
110-
Contains("HEAD detached").IsSelected(),
111-
Contains("master"),
110+
Contains("HEAD detached"),
111+
Contains("master").IsSelected(),
112112
)
113113

114114
// empty commit is gone

0 commit comments

Comments
 (0)