mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-11 11:42:12 +02:00
This makes it so that when the staging view is resized, we keep the same patch line selected (as opposed to the same view line, which may correspond to a different patch line after resizing). It doesn't seem like a terribly important feature for resizing the window, but it is essential when initially entering the staging view: we select the first line of the first hunk in this case, but we do that before layout runs. At layout time the view is then split into unstaged/staged changes, and if this split is horizontal, the view gets narrower and may be wrapped in a different way. With this commit we ensure that the first line of the first hunk is still selected after that.
72 lines
1.5 KiB
Go
72 lines
1.5 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)
|
|
}
|
|
|
|
if self.onFocusFn != nil {
|
|
self.onFocusFn(opts)
|
|
}
|
|
|
|
if self.onRenderToMainFn != nil {
|
|
self.onRenderToMainFn()
|
|
}
|
|
}
|
|
|
|
func (self *SimpleContext) HandleFocusLost(opts types.OnFocusLostOpts) {
|
|
self.GetViewTrait().SetHighlight(false)
|
|
self.view.SetOriginX(0)
|
|
if self.onFocusLostFn != nil {
|
|
self.onFocusLostFn(opts)
|
|
}
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|