diff --git a/docs-master/Config.md b/docs-master/Config.md index 857a4e359..32dc01ecb 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -157,6 +157,9 @@ gui: # staging view. useHunkModeInStagingView: 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' | 'pt' language: auto diff --git a/docs/Config.md b/docs/Config.md index 857a4e359..32dc01ecb 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -157,6 +157,9 @@ gui: # staging view. useHunkModeInStagingView: 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' | 'pt' language: auto diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index 9738186d9..982511db9 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -133,6 +133,8 @@ type GuiConfig struct { WrapLinesInStagingView bool `yaml:"wrapLinesInStagingView"` // If true, hunk selection mode will be enabled by default when entering the staging view. UseHunkModeInStagingView bool `yaml:"useHunkModeInStagingView"` + // 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' | 'pt' 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. @@ -874,13 +876,14 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig { {"commits", "reflog"}, {"stash"}, }, - MainPanelSplitMode: "flexible", - EnlargedSideViewLocation: "left", - WrapLinesInStagingView: true, - UseHunkModeInStagingView: true, - Language: "auto", - TimeFormat: "02 Jan 06", - ShortTimeFormat: time.Kitchen, + MainPanelSplitMode: "flexible", + EnlargedSideViewLocation: "left", + WrapLinesInStagingView: true, + UseHunkModeInStagingView: true, + ShowSelectionInFocusedMainView: false, + Language: "auto", + TimeFormat: "02 Jan 06", + ShortTimeFormat: time.Kitchen, Theme: ThemeConfig{ ActiveBorderColor: []string{"green", "bold"}, SearchingActiveBorderColor: []string{"cyan", "bold"}, diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index 7584b5a12..d684d7fac 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -253,3 +253,7 @@ func (self *BaseContext) Title() string { func (self *BaseContext) TotalContentHeight() int { return self.view.ViewLinesHeight() } + +func (self *BaseContext) SetHighlightOnFocus(value bool) { + self.highlightOnFocus = value +} diff --git a/pkg/gui/context/main_context.go b/pkg/gui/context/main_context.go index c8b6edade..2960f8ffe 100644 --- a/pkg/gui/context/main_context.go +++ b/pkg/gui/context/main_context.go @@ -26,7 +26,7 @@ func NewMainContext( WindowName: windowName, Key: key, Focusable: true, - HighlightOnFocus: false, + HighlightOnFocus: c.UserConfig().Gui.ShowSelectionInFocusedMainView, })), SearchTrait: NewSearchTrait(c), } diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index 6eb6c86e3..73dec8ec0 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -89,6 +89,10 @@ func (self *MainViewController) escape() error { } func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error { + if self.context.GetView().Highlight && !opts.IsDoubleClick { + return nil + } + sidePanelContext := self.c.Context().NextInStack(self.context) if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil { return sidePanelContext.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y) diff --git a/pkg/gui/controllers/view_selection_controller.go b/pkg/gui/controllers/view_selection_controller.go index 1a97a9a30..f14a33d80 100644 --- a/pkg/gui/controllers/view_selection_controller.go +++ b/pkg/gui/controllers/view_selection_controller.go @@ -3,6 +3,7 @@ package controllers import ( "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/samber/lo" ) type ViewSelectionControllerFactory struct { @@ -51,11 +52,22 @@ func (self *ViewSelectionController) GetMouseKeybindings(opts types.KeybindingsO func (self *ViewSelectionController) handleLineChange(delta int) { v := self.Context().GetView() - if delta < 0 { - v.ScrollUp(-delta) + 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, true) } else { - v.ScrollDown(delta) - self.c.ReadLinesToFillView(v) + if delta < 0 { + v.ScrollUp(-delta) + } else { + v.ScrollDown(delta) + self.c.ReadLinesToFillView(v) + } } } @@ -81,7 +93,11 @@ func (self *ViewSelectionController) handleNextPage() error { func (self *ViewSelectionController) handleGotoTop() error { v := self.Context().GetView() - self.handleLineChange(-v.ViewLinesHeight()) + if self.context.GetView().Highlight { + v.FocusPoint(0, 0, true) + } else { + self.handleLineChange(-v.ViewLinesHeight()) + } return nil } @@ -90,7 +106,11 @@ func (self *ViewSelectionController) handleGotoBottom() error { manager.ReadToEnd(func() { self.c.OnUIThread(func() error { v := self.Context().GetView() - self.handleLineChange(v.ViewLinesHeight()) + if self.context.GetView().Highlight { + v.FocusPoint(0, v.ViewLinesHeight()-1, true) + } else { + self.handleLineChange(v.ViewLinesHeight()) + } return nil }) }) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index bde383caf..78729e18c 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -517,6 +517,11 @@ func (gui *Gui) onUserConfigLoaded() error { 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 // 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 diff --git a/schema-master/config.json b/schema-master/config.json index 45a2b9efe..b7c6c4d6a 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -693,6 +693,11 @@ "description": "If true, hunk selection mode will be enabled by default when entering the staging view.", "default": true }, + "showSelectionInFocusedMainView": { + "type": "boolean", + "description": "If true, show a selection when the main view is focused.", + "default": false + }, "language": { "type": "string", "enum": [ diff --git a/schema/config.json b/schema/config.json index 45a2b9efe..b7c6c4d6a 100644 --- a/schema/config.json +++ b/schema/config.json @@ -693,6 +693,11 @@ "description": "If true, hunk selection mode will be enabled by default when entering the staging view.", "default": true }, + "showSelectionInFocusedMainView": { + "type": "boolean", + "description": "If true, show a selection when the main view is focused.", + "default": false + }, "language": { "type": "string", "enum": [