1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Assert that only one controller can set click or render functions on a BaseContext

The rationale for this is the same as in the previous commit; however, for these
functions we only allow a single controller to set them, because they are event
handlers and it doesn't make sense for multiple controllers to handle them.
This commit is contained in:
Stefan Haller
2025-07-10 19:45:04 +02:00
parent 4dfa4e8aa2
commit 12df9d2b42

View File

@ -140,16 +140,25 @@ func (self *BaseContext) ClearAllAttachedControllerFunctions() {
self.mouseKeybindingsFns = nil self.mouseKeybindingsFns = nil
self.onFocusFns = nil self.onFocusFns = nil
self.onFocusLostFns = nil self.onFocusLostFns = nil
self.onClickFn = nil
self.onClickFocusedMainViewFn = nil
self.onRenderToMainFn = nil
} }
func (self *BaseContext) AddOnClickFn(fn func() error) { func (self *BaseContext) AddOnClickFn(fn func() error) {
if fn != nil { if fn != nil {
if self.onClickFn != nil {
panic("only one controller is allowed to set an onClickFn")
}
self.onClickFn = fn self.onClickFn = fn
} }
} }
func (self *BaseContext) AddOnClickFocusedMainViewFn(fn onClickFocusedMainViewFn) { func (self *BaseContext) AddOnClickFocusedMainViewFn(fn onClickFocusedMainViewFn) {
if fn != nil { if fn != nil {
if self.onClickFocusedMainViewFn != nil {
panic("only one controller is allowed to set an onClickFocusedMainViewFn")
}
self.onClickFocusedMainViewFn = fn self.onClickFocusedMainViewFn = fn
} }
} }
@ -164,6 +173,9 @@ func (self *BaseContext) GetOnClickFocusedMainView() onClickFocusedMainViewFn {
func (self *BaseContext) AddOnRenderToMainFn(fn func()) { func (self *BaseContext) AddOnRenderToMainFn(fn func()) {
if fn != nil { if fn != nil {
if self.onRenderToMainFn != nil {
panic("only one controller is allowed to set an onRenderToMainFn")
}
self.onRenderToMainFn = fn self.onRenderToMainFn = fn
} }
} }