diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 941bd3b9c..7988c3697 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -1670,11 +1670,9 @@ func (self *RefreshHelper) refreshView(context types.Context, env refreshEnv) { // the filtered list model is up to date for rendering. self.searchHelper.ReApplyFilter(context) - if env.keepScrollPosition { - self.c.PostRefreshUpdateKeepingScrollPosition(context) - } else { - self.c.PostRefreshUpdate(context) - } + self.c.PostRefreshUpdateWithOptions(context, types.OnFocusOpts{ + KeepScrollPosition: env.keepScrollPosition, + }) self.c.AfterLayout(func() error { // Re-applying the search must be done after re-rendering the view though, diff --git a/pkg/gui/gui_common.go b/pkg/gui/gui_common.go index d92284ea5..86b0455ee 100644 --- a/pkg/gui/gui_common.go +++ b/pkg/gui/gui_common.go @@ -39,11 +39,15 @@ func (self *guiCommon) RefreshFromWorker(opts types.RefreshOptions) { } func (self *guiCommon) PostRefreshUpdate(context types.Context) { - self.gui.postRefreshUpdate(context, false) + self.gui.postRefreshUpdate(context, types.OnFocusOpts{}) +} + +func (self *guiCommon) PostRefreshUpdateWithOptions(context types.Context, opts types.OnFocusOpts) { + self.gui.postRefreshUpdate(context, opts) } func (self *guiCommon) PostRefreshUpdateKeepingScrollPosition(context types.Context) { - self.gui.postRefreshUpdate(context, true) + self.gui.postRefreshUpdate(context, types.OnFocusOpts{KeepScrollPosition: true}) } func (self *guiCommon) RunSubprocessAndRefresh(cmdObj *oscommands.CmdObj) error { diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index ff73b91f6..85fabeb13 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -51,6 +51,9 @@ type IGuiCommon interface { // case would be overkill, although refresh will internally call 'PostRefreshUpdate'. // It re-focuses the context's selection, which scrolls it into view. PostRefreshUpdate(Context) + // Like PostRefreshUpdate, with control over scrolling and whether to update + // the main view. + PostRefreshUpdateWithOptions(Context, OnFocusOpts) // Like PostRefreshUpdate, but leaves the view scrolled where it is. For // refreshes that no user action is behind: those must not move the viewport // away from wherever the user last put it. diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index e9ad48aab..fabbe1edb 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -132,7 +132,7 @@ func (gui *Gui) renderContentOnly() { // postRefreshUpdate is to be called on a context after the state that it depends on has been refreshed // if the context's view is set to another context we do nothing. // if the context's view is the current view we trigger a focus; re-selecting the current item. -func (gui *Gui) postRefreshUpdate(c types.Context, keepScrollPosition bool) { +func (gui *Gui) postRefreshUpdate(c types.Context, opts types.OnFocusOpts) { t := time.Now() defer func() { gui.Log.Infof("postRefreshUpdate for %s took %s", c.GetKey(), time.Since(t)) @@ -141,14 +141,14 @@ func (gui *Gui) postRefreshUpdate(c types.Context, keepScrollPosition bool) { c.HandleRender() if gui.currentViewName() == c.GetViewName() { - c.HandleFocus(types.OnFocusOpts{KeepScrollPosition: keepScrollPosition}) + c.HandleFocus(opts) } else { // The FocusLine call is included in the HandleFocus method which we // call for focused views above; but we need to call it here for // non-focused views to ensure that an inactive selection is painted // correctly, and that integration tests see the up to date selection // state. - c.FocusLine(!keepScrollPosition) + c.FocusLine(!opts.KeepScrollPosition) currentCtx := gui.State.ContextMgr.Current() if currentCtx.GetKey() == context.NORMAL_MAIN_CONTEXT_KEY || currentCtx.GetKey() == context.NORMAL_SECONDARY_CONTEXT_KEY {