mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-01-09 06:21:15 +08:00
It is possible to scroll the selection out of view using the mouse wheel; after doing this, it would sometimes scroll into view by itself again, for example when a background fetch occurred. In the files panel this would even happen every 10s with every regular files refresh. Fix this by adding a scrollIntoView parameter to HandleFocus, which is false by default, and is only set to true from controllers that change the selection.
75 lines
1.6 KiB
Go
75 lines
1.6 KiB
Go
package context
|
|
|
|
import (
|
|
"github.com/jesseduffield/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type SimpleContext struct {
|
|
*BaseContext
|
|
handleRenderFunc func()
|
|
}
|
|
|
|
func NewSimpleContext(baseContext *BaseContext) *SimpleContext {
|
|
return &SimpleContext{
|
|
BaseContext: baseContext,
|
|
}
|
|
}
|
|
|
|
var _ types.Context = &SimpleContext{}
|
|
|
|
// A Display context only renders a view. It has no keybindings and is not focusable.
|
|
func NewDisplayContext(key types.ContextKey, view *gocui.View, windowName string) types.Context {
|
|
return NewSimpleContext(
|
|
NewBaseContext(NewBaseContextOpts{
|
|
Kind: types.DISPLAY_CONTEXT,
|
|
Key: key,
|
|
View: view,
|
|
WindowName: windowName,
|
|
Focusable: false,
|
|
Transient: false,
|
|
}),
|
|
)
|
|
}
|
|
|
|
func (self *SimpleContext) HandleFocus(opts types.OnFocusOpts) {
|
|
if self.highlightOnFocus {
|
|
self.GetViewTrait().SetHighlight(true)
|
|
}
|
|
|
|
for _, fn := range self.onFocusFns {
|
|
fn(opts)
|
|
}
|
|
|
|
if self.onRenderToMainFn != nil {
|
|
self.onRenderToMainFn()
|
|
}
|
|
}
|
|
|
|
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
|
|
self.GetViewTrait().SetHighlight(false)
|
|
self.view.SetOriginX(0)
|
|
for _, fn := range self.onFocusLostFns {
|
|
fn(opts)
|
|
}
|
|
}
|
|
|
|
func (self *SimpleContext) FocusLine(scrollIntoView bool) {
|
|
}
|
|
|
|
func (self *SimpleContext) HandleRender() {
|
|
if self.handleRenderFunc != nil {
|
|
self.handleRenderFunc()
|
|
}
|
|
}
|
|
|
|
func (self *SimpleContext) SetHandleRenderFunc(f func()) {
|
|
self.handleRenderFunc = f
|
|
}
|
|
|
|
func (self *SimpleContext) HandleRenderToMain() {
|
|
if self.onRenderToMainFn != nil {
|
|
self.onRenderToMainFn()
|
|
}
|
|
}
|