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/context.go | |
parent | de0e885c65c7d6505055af490e58c21aad59f67e (diff) |
more efficient context diff size changing
Diffstat (limited to 'pkg/gui/context.go')
-rw-r--r-- | pkg/gui/context.go | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/pkg/gui/context.go b/pkg/gui/context.go index 61c7e60a3..2c9d20f7e 100644 --- a/pkg/gui/context.go +++ b/pkg/gui/context.go @@ -1,6 +1,7 @@ package gui import ( + "errors" "fmt" "github.com/jesseduffield/gocui" @@ -16,10 +17,16 @@ const ( EXTRAS_CONTEXT ) +type OnFocusOpts struct { + ClickedViewName string + ClickedViewLineIdx int +} + type Context interface { - HandleFocus() error + HandleFocus(opts ...OnFocusOpts) error HandleFocusLost() error HandleRender() error + HandleRenderToMain() error GetKind() ContextKind GetViewName() string GetWindowName() string @@ -81,15 +88,20 @@ func (gui *Gui) replaceContext(c Context) error { return nil } -func (gui *Gui) pushContext(c Context) error { +func (gui *Gui) pushContext(c Context, opts ...OnFocusOpts) error { + // using triple dot but you should only ever pass one of these opt structs + if len(opts) > 1 { + return errors.New("cannot pass multiple opts to pushContext") + } + gui.g.Update(func(*gocui.Gui) error { - return gui.pushContextDirect(c) + return gui.pushContextDirect(c, opts...) }) return nil } -func (gui *Gui) pushContextDirect(c Context) error { +func (gui *Gui) pushContextDirect(c Context, opts ...OnFocusOpts) error { gui.State.ContextManager.Lock() // push onto stack @@ -114,7 +126,7 @@ func (gui *Gui) pushContextDirect(c Context) error { gui.State.ContextManager.Unlock() - return gui.activateContext(c) + return gui.activateContext(c, opts...) } // asynchronous code idea: functions return an error via a channel, when done @@ -206,7 +218,7 @@ func (gui *Gui) postRefreshUpdate(c Context) error { return nil } -func (gui *Gui) activateContext(c Context) error { +func (gui *Gui) activateContext(c Context, opts ...OnFocusOpts) error { viewName := c.GetViewName() v, err := gui.g.View(viewName) if err != nil { @@ -249,7 +261,7 @@ func (gui *Gui) activateContext(c Context) error { } gui.renderOptionsMap(optionsMap) - if err := c.HandleFocus(); err != nil { + if err := c.HandleFocus(opts...); err != nil { return err } |