mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-06 14:06:32 -04:00
The mode of a diff view's selection lives on the context of the pane showing it, and until now only the controllers that drive the selection needed to name that pane, all of which have it as the concrete context it is. A side panel is about to be handed the pane a command was invoked in, so that it can act on what is selected there — and it can't be handed a context, the interface it is handed one through being declared where a context's concrete type isn't available. So the state moves to where such an interface can speak of it, and the panes gain one: a context that has a diff selection. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package context
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/gocui"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
)
|
|
|
|
type MainContext struct {
|
|
*SimpleContext
|
|
*SearchTrait
|
|
|
|
diffSelect types.DiffSelectState
|
|
// selectableContentRenderKey names the render whose content HasSelectableContent
|
|
// was worked out from. What there is to select is a property of the content, so an
|
|
// answer about the content of another render says nothing about this one.
|
|
selectableContentRenderKey string
|
|
}
|
|
|
|
var (
|
|
_ types.ISearchableContext = (*MainContext)(nil)
|
|
_ types.DiffPaneContext = (*MainContext)(nil)
|
|
)
|
|
|
|
// DiffSelectState returns the focused main view's selection mode state, for the
|
|
// controllers to read and mutate directly.
|
|
func (self *MainContext) DiffSelectState() *types.DiffSelectState {
|
|
return &self.diffSelect
|
|
}
|
|
|
|
// ResetDiffSelectMode returns the pane's selection to the default mode — a single
|
|
// line, no range — for whenever it is established from scratch rather than moved. The
|
|
// view's range anchor is cleared too, so the next render highlights the cursor line
|
|
// only.
|
|
func (self *MainContext) ResetDiffSelectMode() {
|
|
self.diffSelect.Mode = types.DiffSelectModeLine
|
|
self.diffSelect.RangeIsSticky = false
|
|
self.diffSelect.UserEnabledHunkMode = false
|
|
self.GetView().CancelRangeSelect()
|
|
}
|
|
|
|
// SelectableContentRenderKey returns the render HasSelectableContent describes (see
|
|
// selectableContentRenderKey).
|
|
func (self *MainContext) SelectableContentRenderKey() string {
|
|
return self.selectableContentRenderKey
|
|
}
|
|
|
|
// SetSelectableContentRenderKey records which render HasSelectableContent describes.
|
|
func (self *MainContext) SetSelectableContentRenderKey(key string) {
|
|
self.selectableContentRenderKey = key
|
|
}
|
|
|
|
func NewMainContext(
|
|
view *gocui.View,
|
|
windowName string,
|
|
key types.ContextKey,
|
|
c *ContextCommon,
|
|
) *MainContext {
|
|
ctx := &MainContext{
|
|
SimpleContext: NewSimpleContext(
|
|
NewBaseContext(NewBaseContextOpts{
|
|
Kind: types.MAIN_CONTEXT,
|
|
View: view,
|
|
WindowName: windowName,
|
|
Key: key,
|
|
Focusable: true,
|
|
})),
|
|
SearchTrait: NewSearchTrait(c),
|
|
}
|
|
|
|
return ctx
|
|
}
|
|
|
|
func (self *MainContext) ModelSearchResults(searchStr string, caseSensitive bool) []gocui.SearchPosition {
|
|
return nil
|
|
}
|
|
|
|
// When selecting a search result, collapse a range selection (whether sticky or not)
|
|
// or a hunk selection to just the matching line.
|
|
func (self *MainContext) OnSearchSelect(int) {
|
|
self.ResetDiffSelectMode()
|
|
}
|