mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-27 22:38:09 +02:00
Allow more than one controller to attach OnFocus/OnFocusLost functions
Trying to do this would previously have the second one silently overwrite the first one's. We don't currently have this in lazygit, but I ran into the situation once during development, and it can lead to bugs that are hard to diagnose. Instead of holding a list of functions, we could also have added a panic in case the function was set already; this would have been good enough for the current state, and enough to catch mistakes early in the future. However, I decided to allow multiple controllers to attach these functions, because I can't see a reason not to.
This commit is contained in:
@@ -37,8 +37,8 @@ func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) {
|
||||
self.GetViewTrait().SetHighlight(true)
|
||||
}
|
||||
|
||||
if self.onFocusFn != nil {
|
||||
self.onFocusFn(opts)
|
||||
for _, fn := range self.onFocusFns {
|
||||
fn(opts)
|
||||
}
|
||||
|
||||
if self.onRenderToMainFn != nil {
|
||||
@@ -49,8 +49,8 @@ func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) {
|
||||
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
|
||||
self.GetViewTrait().SetHighlight(false)
|
||||
self.view.SetOriginX(0)
|
||||
if self.onFocusLostFn != nil {
|
||||
self.onFocusLostFn(opts)
|
||||
for _, fn := range self.onFocusLostFns {
|
||||
fn(opts)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user