mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Add user config gui.showSelectionInFocusedMainView
This commit is contained in:
parent
5f149e2d07
commit
e76f1d6c1f
8 changed files with 67 additions and 23 deletions
|
@ -113,6 +113,9 @@ gui:
|
||||||
# paragraphs of markdown text.
|
# paragraphs of markdown text.
|
||||||
wrapLinesInStagingView: true
|
wrapLinesInStagingView: true
|
||||||
|
|
||||||
|
# If true, show a selection when the main view is focused.
|
||||||
|
showSelectionInFocusedMainView: false
|
||||||
|
|
||||||
# One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
|
# One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
|
||||||
language: auto
|
language: auto
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,8 @@ type GuiConfig struct {
|
||||||
// makes it much easier to work with diffs that have long lines, e.g.
|
// makes it much easier to work with diffs that have long lines, e.g.
|
||||||
// paragraphs of markdown text.
|
// paragraphs of markdown text.
|
||||||
WrapLinesInStagingView bool `yaml:"wrapLinesInStagingView"`
|
WrapLinesInStagingView bool `yaml:"wrapLinesInStagingView"`
|
||||||
|
// If true, show a selection when the main view is focused.
|
||||||
|
ShowSelectionInFocusedMainView bool `yaml:"showSelectionInFocusedMainView"`
|
||||||
// One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
|
// One of 'auto' (default) | 'en' | 'zh-CN' | 'zh-TW' | 'pl' | 'nl' | 'ja' | 'ko' | 'ru'
|
||||||
Language string `yaml:"language" jsonschema:"enum=auto,enum=en,enum=zh-TW,enum=zh-CN,enum=pl,enum=nl,enum=ja,enum=ko,enum=ru"`
|
Language string `yaml:"language" jsonschema:"enum=auto,enum=en,enum=zh-TW,enum=zh-CN,enum=pl,enum=nl,enum=ja,enum=ko,enum=ru"`
|
||||||
// Format used when displaying time e.g. commit time.
|
// Format used when displaying time e.g. commit time.
|
||||||
|
@ -749,6 +751,7 @@ func GetDefaultConfig() *UserConfig {
|
||||||
MainPanelSplitMode: "flexible",
|
MainPanelSplitMode: "flexible",
|
||||||
EnlargedSideViewLocation: "left",
|
EnlargedSideViewLocation: "left",
|
||||||
WrapLinesInStagingView: true,
|
WrapLinesInStagingView: true,
|
||||||
|
ShowSelectionInFocusedMainView: false,
|
||||||
Language: "auto",
|
Language: "auto",
|
||||||
TimeFormat: "02 Jan 06",
|
TimeFormat: "02 Jan 06",
|
||||||
ShortTimeFormat: time.Kitchen,
|
ShortTimeFormat: time.Kitchen,
|
||||||
|
|
|
@ -228,3 +228,7 @@ func (self *BaseContext) Title() string {
|
||||||
func (self *BaseContext) TotalContentHeight() int {
|
func (self *BaseContext) TotalContentHeight() int {
|
||||||
return self.view.ViewLinesHeight()
|
return self.view.ViewLinesHeight()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *BaseContext) SetHighlightOnFocus(value bool) {
|
||||||
|
self.highlightOnFocus = value
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func NewMainContext(
|
||||||
WindowName: windowName,
|
WindowName: windowName,
|
||||||
Key: key,
|
Key: key,
|
||||||
Focusable: true,
|
Focusable: true,
|
||||||
HighlightOnFocus: false,
|
HighlightOnFocus: c.UserConfig().Gui.ShowSelectionInFocusedMainView,
|
||||||
})),
|
})),
|
||||||
SearchTrait: NewSearchTrait(c),
|
SearchTrait: NewSearchTrait(c),
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,10 @@ func (self *MainViewController) escape() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *MainViewController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
func (self *MainViewController) onClick(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
if self.context.GetView().Highlight && opts.Y != opts.PreviousY {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
parentCtx := self.context.GetParentContext()
|
parentCtx := self.context.GetParentContext()
|
||||||
if parentCtx.GetOnClickFocusedMainView() != nil {
|
if parentCtx.GetOnClickFocusedMainView() != nil {
|
||||||
return parentCtx.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
|
return parentCtx.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package controllers
|
||||||
import (
|
import (
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ViewSelectionControllerFactory struct {
|
type ViewSelectionControllerFactory struct {
|
||||||
|
@ -61,12 +62,23 @@ func (self *ViewSelectionController) handleLineChange(delta int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
v := self.Context().GetView()
|
v := self.Context().GetView()
|
||||||
|
if self.context.GetView().Highlight {
|
||||||
|
lineIdxBefore := v.CursorY() + v.OriginY()
|
||||||
|
lineIdxAfter := lo.Clamp(lineIdxBefore+delta, 0, v.ViewLinesHeight()-1)
|
||||||
|
if delta == -1 {
|
||||||
|
checkScrollUp(self.Context().GetViewTrait(), self.c.UserConfig(), lineIdxBefore, lineIdxAfter)
|
||||||
|
} else if delta == 1 {
|
||||||
|
checkScrollDown(self.Context().GetViewTrait(), self.c.UserConfig(), lineIdxBefore, lineIdxAfter)
|
||||||
|
}
|
||||||
|
v.FocusPoint(0, lineIdxAfter)
|
||||||
|
} else {
|
||||||
if delta < 0 {
|
if delta < 0 {
|
||||||
v.ScrollUp(-delta)
|
v.ScrollUp(-delta)
|
||||||
} else {
|
} else {
|
||||||
v.ScrollDown(delta)
|
v.ScrollDown(delta)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *ViewSelectionController) handlePrevLine() error {
|
func (self *ViewSelectionController) handlePrevLine() error {
|
||||||
self.handleLineChange(-1)
|
self.handleLineChange(-1)
|
||||||
|
@ -90,7 +102,11 @@ func (self *ViewSelectionController) handleNextPage() error {
|
||||||
|
|
||||||
func (self *ViewSelectionController) handleGotoTop() error {
|
func (self *ViewSelectionController) handleGotoTop() error {
|
||||||
v := self.Context().GetView()
|
v := self.Context().GetView()
|
||||||
|
if self.context.GetView().Highlight {
|
||||||
|
v.FocusPoint(0, 0)
|
||||||
|
} else {
|
||||||
self.handleLineChange(-v.ViewLinesHeight())
|
self.handleLineChange(-v.ViewLinesHeight())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +115,11 @@ func (self *ViewSelectionController) handleGotoBottom() error {
|
||||||
manager.ReadToEnd(func() {
|
manager.ReadToEnd(func() {
|
||||||
self.c.OnUIThread(func() error {
|
self.c.OnUIThread(func() error {
|
||||||
v := self.Context().GetView()
|
v := self.Context().GetView()
|
||||||
|
if self.context.GetView().Highlight {
|
||||||
|
v.FocusPoint(0, v.ViewLinesHeight()-1)
|
||||||
|
} else {
|
||||||
self.handleLineChange(v.ViewLinesHeight())
|
self.handleLineChange(v.ViewLinesHeight())
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -446,6 +446,11 @@ func (gui *Gui) onUserConfigLoaded() error {
|
||||||
|
|
||||||
gui.g.Mouse = userConfig.Gui.MouseEvents
|
gui.g.Mouse = userConfig.Gui.MouseEvents
|
||||||
|
|
||||||
|
if gui.State != nil {
|
||||||
|
gui.Contexts().Normal.SetHighlightOnFocus(userConfig.Gui.ShowSelectionInFocusedMainView)
|
||||||
|
gui.Contexts().NormalSecondary.SetHighlightOnFocus(userConfig.Gui.ShowSelectionInFocusedMainView)
|
||||||
|
}
|
||||||
|
|
||||||
// originally we could only hide the command log permanently via the config
|
// originally we could only hide the command log permanently via the config
|
||||||
// but now we do it via state. So we need to still support the config for the
|
// but now we do it via state. So we need to still support the config for the
|
||||||
// sake of backwards compatibility. We're making use of short circuiting here
|
// sake of backwards compatibility. We're making use of short circuiting here
|
||||||
|
|
|
@ -528,6 +528,11 @@
|
||||||
"description": "If true, wrap lines in the staging view to the width of the view. This\nmakes it much easier to work with diffs that have long lines, e.g.\nparagraphs of markdown text.",
|
"description": "If true, wrap lines in the staging view to the width of the view. This\nmakes it much easier to work with diffs that have long lines, e.g.\nparagraphs of markdown text.",
|
||||||
"default": true
|
"default": true
|
||||||
},
|
},
|
||||||
|
"showSelectionInFocusedMainView": {
|
||||||
|
"type": "boolean",
|
||||||
|
"description": "If true, show a selection when the main view is focused.",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": [
|
"enum": [
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue