diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-11-21 12:48:49 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-06 22:37:28 +1100 |
commit | 1996eddd9124709431ced14b1650ae5a50963be7 (patch) | |
tree | 021b88b94139b21beae4cae92b9f0a119e7361f2 /pkg/gui/list_context.go | |
parent | de0e885c65c7d6505055af490e58c21aad59f67e (diff) |
more efficient context diff size changing
Diffstat (limited to 'pkg/gui/list_context.go')
-rw-r--r-- | pkg/gui/list_context.go | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index a7c47e480..445b0f3d0 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -9,7 +9,8 @@ import ( type ListContext struct { GetItemsLength func() int GetDisplayStrings func(startIdx int, length int) [][]string - OnFocus func() error + OnFocus func(...OnFocusOpts) error + OnRenderToMain func(...OnFocusOpts) error OnFocusLost func() error OnClickSelectedItem func() error @@ -29,7 +30,6 @@ type ListContext struct { type IListContext interface { GetSelectedItem() (ListItem, bool) GetSelectedItemId() string - OnRender() error handlePrevLine() error handleNextLine() error handleScrollLeft() error @@ -42,6 +42,7 @@ type IListContext interface { handleClick() error onSearchSelect(selectedLineIdx int) error FocusLine() + HandleRenderToMain() error GetPanelState() IListPanelState @@ -101,7 +102,7 @@ func (self *ListContext) GetSelectedItemId() string { } // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view -func (self *ListContext) OnRender() error { +func (self *ListContext) HandleRender() error { view, err := self.Gui.g.View(self.ViewName) if err != nil { return nil @@ -131,7 +132,7 @@ func (self *ListContext) HandleFocusLost() error { return nil } -func (self *ListContext) HandleFocus() error { +func (self *ListContext) HandleFocus(opts ...OnFocusOpts) error { if self.Gui.popupPanelFocused() { return nil } @@ -143,14 +144,18 @@ func (self *ListContext) HandleFocus() error { } if self.OnFocus != nil { - return self.OnFocus() + if err := self.OnFocus(opts...); err != nil { + return err + } } - return nil -} + if self.OnRenderToMain != nil { + if err := self.OnRenderToMain(opts...); err != nil { + return err + } + } -func (self *ListContext) HandleRender() error { - return self.OnRender() + return nil } func (self *ListContext) handlePrevLine() error { @@ -268,3 +273,11 @@ func (self *ListContext) onSearchSelect(selectedLineIdx int) error { self.GetPanelState().SetSelectedLineIdx(selectedLineIdx) return self.HandleFocus() } + +func (self *ListContext) HandleRenderToMain() error { + if self.OnRenderToMain != nil { + return self.OnRenderToMain() + } + + return nil +} |