diff --git a/pkg/gui/context/patch_explorer_context.go b/pkg/gui/context/patch_explorer_context.go index ab0d3f472..eb79dce86 100644 --- a/pkg/gui/context/patch_explorer_context.go +++ b/pkg/gui/context/patch_explorer_context.go @@ -39,12 +39,13 @@ func NewPatchExplorerContext( mutex: &deadlock.Mutex{}, getIncludedLineIndices: getIncludedLineIndices, SimpleContext: NewSimpleContext(NewBaseContext(NewBaseContextOpts{ - View: view, - WindowName: windowName, - Key: key, - Kind: types.MAIN_CONTEXT, - Focusable: true, - HighlightOnFocus: true, + View: view, + WindowName: windowName, + Key: key, + Kind: types.MAIN_CONTEXT, + Focusable: true, + HighlightOnFocus: true, + NeedsRerenderOnWidthChange: types.NEEDS_RERENDER_ON_WIDTH_CHANGE_WHEN_WIDTH_CHANGES, })), SearchTrait: NewSearchTrait(c), } @@ -58,6 +59,8 @@ func NewPatchExplorerContext( }), ) + ctx.SetHandleRenderFunc(ctx.OnViewWidthChanged) + return ctx } @@ -140,3 +143,11 @@ func (self *PatchExplorerContext) GetMutex() *deadlock.Mutex { func (self *PatchExplorerContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition { return nil } + +func (self *PatchExplorerContext) OnViewWidthChanged() { + if state := self.GetState(); state != nil { + state.OnViewWidthChanged(self.GetView()) + self.setContent() + self.RenderAndFocus() + } +} diff --git a/pkg/gui/context/simple_context.go b/pkg/gui/context/simple_context.go index d78db7190..579f975e6 100644 --- a/pkg/gui/context/simple_context.go +++ b/pkg/gui/context/simple_context.go @@ -7,6 +7,7 @@ import ( type SimpleContext struct { *BaseContext + handleRenderFunc func() } func NewSimpleContext(baseContext *BaseContext) *SimpleContext { @@ -54,6 +55,13 @@ func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) { } func (self *SimpleContext) HandleRender() { + if self.handleRenderFunc != nil { + self.handleRenderFunc() + } +} + +func (self *SimpleContext) SetHandleRenderFunc(f func()) { + self.handleRenderFunc = f } func (self *SimpleContext) HandleRenderToMain() { diff --git a/pkg/gui/patch_exploring/state.go b/pkg/gui/patch_exploring/state.go index 2711dd2c7..c10807c8c 100644 --- a/pkg/gui/patch_exploring/state.go +++ b/pkg/gui/patch_exploring/state.go @@ -90,6 +90,23 @@ func NewState(diff string, selectedLineIdx int, view *gocui.View, oldState *Stat } } +func (s *State) OnViewWidthChanged(view *gocui.View) { + if !view.Wrap { + return + } + + selectedPatchLineIdx := s.patchLineIndices[s.selectedLineIdx] + var rangeStartPatchLineIdx int + if s.selectMode == RANGE { + rangeStartPatchLineIdx = s.patchLineIndices[s.rangeStartLineIdx] + } + s.viewLineIndices, s.patchLineIndices = wrapPatchLines(s.diff, view) + s.selectedLineIdx = s.viewLineIndices[selectedPatchLineIdx] + if s.selectMode == RANGE { + s.rangeStartLineIdx = s.viewLineIndices[rangeStartPatchLineIdx] + } +} + func (s *State) GetSelectedPatchLineIdx() int { return s.patchLineIndices[s.selectedLineIdx] }