Skip to content

Commit 418dae0

Browse files
committed
Update search position (match x of y) when changing the selection in a list view
or in the staging view.
1 parent 0bbd279 commit 418dae0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/gui/context/list_context_trait.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,19 @@ type ListContextTrait struct {
2424
// If renderOnlyVisibleLines is true, needRerenderVisibleLines indicates whether we need to
2525
// rerender the visible lines e.g. because the scroll position changed
2626
needRerenderVisibleLines bool
27+
28+
inOnSearchSelect bool
2729
}
2830

2931
func (self *ListContextTrait) IsListContext() {}
3032

3133
func (self *ListContextTrait) FocusLine(scrollIntoView bool) {
3234
self.Context.FocusLine(scrollIntoView)
3335

36+
// Need to capture this in a local variable because by the time the AfterLayout function runs,
37+
// the field will have been reset to false already
38+
inOnSearchSelect := self.inOnSearchSelect
39+
3440
// Doing this at the end of the layout function because we need the view to be
3541
// resized before we focus the line, otherwise if we're in accordion mode
3642
// the view could be squashed and won't know how to adjust the cursor/origin.
@@ -40,6 +46,9 @@ func (self *ListContextTrait) FocusLine(scrollIntoView bool) {
4046

4147
self.GetViewTrait().FocusPoint(
4248
self.ModelIndexToViewIndex(self.list.GetSelectedLineIdx()), scrollIntoView)
49+
if !inOnSearchSelect {
50+
self.GetView().SetNearestSearchPosition()
51+
}
4352

4453
selectRangeIndex, isSelectingRange := self.list.GetRangeStartIdx()
4554
if isSelectingRange {
@@ -119,7 +128,9 @@ func (self *ListContextTrait) HandleRender() {
119128

120129
func (self *ListContextTrait) OnSearchSelect(selectedLineIdx int) {
121130
self.GetList().SetSelection(self.ViewIndexToModelIndex(selectedLineIdx))
131+
self.inOnSearchSelect = true
122132
self.HandleFocus(types.OnFocusOpts{})
133+
self.inOnSearchSelect = false
123134
}
124135

125136
func (self *ListContextTrait) IsItemVisible(item types.HasUrn) bool {

pkg/gui/context/patch_explorer_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type PatchExplorerContext struct {
1616
getIncludedLineIndices func() []int
1717
c *ContextCommon
1818
mutex deadlock.Mutex
19+
20+
inOnSearchSelect bool
1921
}
2022

2123
var (
@@ -53,7 +55,9 @@ func NewPatchExplorerContext(
5355
ctx.GetView().SetOnSelectItem(func(selectedLineIdx int) {
5456
ctx.GetMutex().Lock()
5557
defer ctx.GetMutex().Unlock()
58+
ctx.inOnSearchSelect = true
5659
ctx.NavigateTo(selectedLineIdx)
60+
ctx.inOnSearchSelect = false
5761
})
5862

5963
ctx.SetHandleRenderFunc(ctx.OnViewWidthChanged)
@@ -111,6 +115,10 @@ func (self *PatchExplorerContext) FocusSelection() {
111115
// As far as the view is concerned, we are always selecting a range
112116
view.SetRangeSelectStart(startIdx)
113117
view.SetCursorY(endIdx - newOriginY)
118+
119+
if !self.inOnSearchSelect {
120+
view.SetNearestSearchPosition()
121+
}
114122
}
115123

116124
func (self *PatchExplorerContext) GetContentToRender() string {

0 commit comments

Comments
 (0)