diff --git a/docs-master/Config.md b/docs-master/Config.md index 32dc01ecb..857a4e359 100644 --- a/docs-master/Config.md +++ b/docs-master/Config.md @@ -157,9 +157,6 @@ 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-master/keybindings/Keybindings_en.md b/docs-master/keybindings/Keybindings_en.md index 3ec731bf2..9eee70480 100644 --- a/docs-master/keybindings/Keybindings_en.md +++ b/docs-master/keybindings/Keybindings_en.md @@ -224,6 +224,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | Scroll up | | | `` `` | Switch view | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Search the current view by text | | ## Main panel (patch building) @@ -329,6 +330,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | Switch view | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Search the current view by text | | ## Stash diff --git a/docs-master/keybindings/Keybindings_ja.md b/docs-master/keybindings/Keybindings_ja.md index 6a3d9b5c1..f67cdaed9 100644 --- a/docs-master/keybindings/Keybindings_ja.md +++ b/docs-master/keybindings/Keybindings_ja.md @@ -193,6 +193,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | ビューを切り替え | 他のビュー(ステージされた変更/ステージされていない変更)に切り替えます。 | | `` `` | サイドパネルに戻る | | +| `` `` | Show/hide selection | | | `` / `` | 現在のビューをテキストで検索 | | ## タグ @@ -306,6 +307,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | 上にスクロール | | | `` `` | ビューを切り替え | 他のビュー(ステージされた変更/ステージされていない変更)に切り替えます。 | | `` `` | サイドパネルに戻る | | +| `` `` | Show/hide selection | | | `` / `` | 現在のビューをテキストで検索 | | ## メニュー diff --git a/docs-master/keybindings/Keybindings_ko.md b/docs-master/keybindings/Keybindings_ko.md index a0e5d84dc..4521b468b 100644 --- a/docs-master/keybindings/Keybindings_ko.md +++ b/docs-master/keybindings/Keybindings_ko.md @@ -85,6 +85,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | 패널 전환 | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | 검색 시작 | | ## Stash @@ -163,6 +164,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | 위로 스크롤 | | | `` `` | 패널 전환 | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | 검색 시작 | | ## 메인 패널 (Patch Building) diff --git a/docs-master/keybindings/Keybindings_nl.md b/docs-master/keybindings/Keybindings_nl.md index 7d95e72dd..1339556a9 100644 --- a/docs-master/keybindings/Keybindings_nl.md +++ b/docs-master/keybindings/Keybindings_nl.md @@ -232,6 +232,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | Scroll omhoog | | | `` `` | Ga naar een ander paneel | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Start met zoeken | | ## Patch bouwen @@ -307,6 +308,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | Ga naar een ander paneel | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Start met zoeken | | ## Staging diff --git a/docs-master/keybindings/Keybindings_pl.md b/docs-master/keybindings/Keybindings_pl.md index ba46f7c46..b91a75ea1 100644 --- a/docs-master/keybindings/Keybindings_pl.md +++ b/docs-master/keybindings/Keybindings_pl.md @@ -100,6 +100,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | Przełącz widok | Przełącz na inny widok (zatwierdzone/niezatwierdzone zmiany). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Szukaj w bieżącym widoku po tekście | | ## Drzewa pracy @@ -202,6 +203,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | Przewiń w górę | | | `` `` | Przełącz widok | Przełącz na inny widok (zatwierdzone/niezatwierdzone zmiany). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Szukaj w bieżącym widoku po tekście | | ## Panel główny (scalanie) diff --git a/docs-master/keybindings/Keybindings_pt.md b/docs-master/keybindings/Keybindings_pt.md index 3071613be..50e08defa 100644 --- a/docs-master/keybindings/Keybindings_pt.md +++ b/docs-master/keybindings/Keybindings_pt.md @@ -236,6 +236,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | Rolar para cima | | | `` `` | Mudar de visão | Alternar para outra visão (staged/não processadas alterações). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Pesquisar na visualização atual por texto | | ## Painel Principal (preparação) @@ -338,6 +339,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | Mudar de visão | Alternar para outra visão (staged/não processadas alterações). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Pesquisar na visualização atual por texto | | ## Stash diff --git a/docs-master/keybindings/Keybindings_ru.md b/docs-master/keybindings/Keybindings_ru.md index 3d03f9ca6..e4edf7ba7 100644 --- a/docs-master/keybindings/Keybindings_ru.md +++ b/docs-master/keybindings/Keybindings_ru.md @@ -75,6 +75,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | Переключиться на другую панель (проиндексированные/непроиндексированные изменения) | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Найти | | ## Главная панель (Индексирование) @@ -107,6 +108,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | Прокрутить вверх | | | `` `` | Переключиться на другую панель (проиндексированные/непроиндексированные изменения) | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | Найти | | ## Главная панель (Слияние) diff --git a/docs-master/keybindings/Keybindings_zh-CN.md b/docs-master/keybindings/Keybindings_zh-CN.md index 9819cb982..bef685944 100644 --- a/docs-master/keybindings/Keybindings_zh-CN.md +++ b/docs-master/keybindings/Keybindings_zh-CN.md @@ -287,6 +287,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | 切换到其他面板 | 切换到其他视图(已暂存/未暂存的变更) | | `` `` | 退出回到侧边面板 | | +| `` `` | Show/hide selection | | | `` / `` | 开始搜索 | | ## 正在合并 @@ -335,6 +336,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | 向上滚动 | | | `` `` | 切换到其他面板 | 切换到其他视图(已暂存/未暂存的变更) | | `` `` | 退出回到侧边面板 | | +| `` `` | Show/hide selection | | | `` / `` | 开始搜索 | | ## 状态 diff --git a/docs-master/keybindings/Keybindings_zh-TW.md b/docs-master/keybindings/Keybindings_zh-TW.md index 1706a627e..606c2c06d 100644 --- a/docs-master/keybindings/Keybindings_zh-TW.md +++ b/docs-master/keybindings/Keybindings_zh-TW.md @@ -83,6 +83,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct | `` (fn+down) `` | 向上捲動 | | | `` `` | 切換至另一個面板 (已預存/未預存更改) | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | 搜尋 | | ## 主面板(合併) @@ -364,6 +365,7 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct |-----|--------|-------------| | `` `` | 切換至另一個面板 (已預存/未預存更改) | Switch to other view (staged/unstaged changes). | | `` `` | Exit back to side panel | | +| `` `` | Show/hide selection | | | `` / `` | 搜尋 | | ## 狀態 diff --git a/docs/Config.md b/docs/Config.md index 32dc01ecb..857a4e359 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -157,9 +157,6 @@ 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 982511db9..9738186d9 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -133,8 +133,6 @@ 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. @@ -876,14 +874,13 @@ func GetDefaultConfigForPlatform(platform string) *UserConfig { {"commits", "reflog"}, {"stash"}, }, - MainPanelSplitMode: "flexible", - EnlargedSideViewLocation: "left", - WrapLinesInStagingView: true, - UseHunkModeInStagingView: true, - ShowSelectionInFocusedMainView: false, - Language: "auto", - TimeFormat: "02 Jan 06", - ShortTimeFormat: time.Kitchen, + MainPanelSplitMode: "flexible", + EnlargedSideViewLocation: "left", + WrapLinesInStagingView: true, + UseHunkModeInStagingView: true, + 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 d684d7fac..7584b5a12 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -253,7 +253,3 @@ 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 2960f8ffe..c8b6edade 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: c.UserConfig().Gui.ShowSelectionInFocusedMainView, + HighlightOnFocus: false, })), SearchTrait: NewSearchTrait(c), } diff --git a/pkg/gui/controllers/main_view_controller.go b/pkg/gui/controllers/main_view_controller.go index 65fcad01c..77b9b949f 100644 --- a/pkg/gui/controllers/main_view_controller.go +++ b/pkg/gui/controllers/main_view_controller.go @@ -4,6 +4,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/samber/lo" ) type MainViewController struct { @@ -30,11 +31,13 @@ func NewMainViewController( } func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { - var goIntoDescription string - // We only want to show the "enter" menu item if the user config is true; - // leaving the description empty causes it to be hidden - if self.c.UserConfig().Gui.ShowSelectionInFocusedMainView { - goIntoDescription = self.c.Tr.EnterStaging + // When a selection is shown, we surface the bindings that act on it + // (enter to dive into staging, escape to hide the selection). + selectionShown := self.context.GetView().Highlight + + var enterDescription string + if selectionShown { + enterDescription = self.c.Tr.EnterStaging } return []*types.Binding{ @@ -52,9 +55,16 @@ func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*ty DisplayOnScreen: true, }, { - Keys: opts.GetKeys(opts.Config.Universal.GoInto), - Handler: self.enter, - Description: goIntoDescription, + Keys: opts.GetKeys(opts.Config.Universal.Select), + Handler: self.toggleSelection, + Description: self.c.Tr.ToggleSelectionInFocusedMainView, + DisplayOnScreen: !selectionShown, + }, + { + Keys: opts.GetKeys(opts.Config.Universal.GoInto), + Handler: self.enter, + Description: enterDescription, + DisplayOnScreen: selectionShown, }, { // overriding this because we want to read all of the task's output before we start searching @@ -87,11 +97,14 @@ func (self *MainViewController) Context() types.Context { return self.context } +// Transient focus shifts (popups, search) leave HighlightInactive=true on our +// view (set by ContextMgr.Activate when a different view becomes current). Our +// context's highlightOnFocus is false, so SimpleContext.HandleFocus never +// resets it. Reset it here on the way back in, so that if we still hold a +// selection it's drawn as active. The flag is a no-op when Highlight is false. func (self *MainViewController) GetOnFocus() func(types.OnFocusOpts) { - return func(opts types.OnFocusOpts) { - if opts.ClickedWindowName != "" { - self.context.GetView().FocusPoint(0, opts.ClickedViewLineIdx, false) - } + return func(types.OnFocusOpts) { + self.context.GetView().HighlightInactive = false } } @@ -104,11 +117,33 @@ func (self *MainViewController) togglePanel() error { } func (self *MainViewController) escape() error { + v := self.context.GetView() + if v.Highlight { + v.Highlight = false + return nil + } self.c.Context().Pop() return nil } +func (self *MainViewController) toggleSelection() error { + v := self.context.GetView() + if v.Highlight { + v.Highlight = false + return nil + } + v.Highlight = true + v.HighlightInactive = false + lineIdx := v.OriginY() + v.InnerHeight()/2 + lineIdx = lo.Clamp(lineIdx, 0, v.ViewLinesHeight()-1) + v.FocusPoint(0, lineIdx, false) + return nil +} + func (self *MainViewController) enter() error { + if !self.context.GetView().Highlight { + return nil + } sidePanelContext := self.c.Context().NextInStack(self.context) if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil { return sidePanelContext.GetOnClickFocusedMainView()( diff --git a/pkg/gui/controllers/switch_to_focused_main_view_controller.go b/pkg/gui/controllers/switch_to_focused_main_view_controller.go index 3c3ecd207..5606a0bab 100644 --- a/pkg/gui/controllers/switch_to_focused_main_view_controller.go +++ b/pkg/gui/controllers/switch_to_focused_main_view_controller.go @@ -3,7 +3,6 @@ package controllers import ( "github.com/jesseduffield/lazygit/pkg/gocui" "github.com/jesseduffield/lazygit/pkg/gui/types" - "github.com/samber/lo" ) // This controller is for all contexts that can focus their main view. @@ -62,29 +61,21 @@ func (self *SwitchToFocusedMainViewController) Context() types.Context { } func (self *SwitchToFocusedMainViewController) onClickMain(opts gocui.ViewMouseBindingOpts) error { - return self.focusMainView(self.c.Contexts().Normal, opts.Y) + return self.focusMainView(self.c.Contexts().Normal) } func (self *SwitchToFocusedMainViewController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error { - return self.focusMainView(self.c.Contexts().NormalSecondary, opts.Y) + return self.focusMainView(self.c.Contexts().NormalSecondary) } func (self *SwitchToFocusedMainViewController) handleFocusMainView() error { - return self.focusMainView(self.c.Contexts().Normal, -1) + return self.focusMainView(self.c.Contexts().Normal) } -func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context, clickedViewLineIdx int) error { +func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error { if context, ok := mainViewContext.(types.ISearchableContext); ok { context.ClearSearchString() } - onFocusOpts := types.OnFocusOpts{ClickedWindowName: mainViewContext.GetWindowName()} - if clickedViewLineIdx >= 0 { - onFocusOpts.ClickedViewLineIdx = clickedViewLineIdx - } else { - mainView := mainViewContext.GetView() - lineIdx := mainView.OriginY() + mainView.Height()/2 - onFocusOpts.ClickedViewLineIdx = lo.Clamp(lineIdx, 0, mainView.LinesHeight()-1) - } - self.c.Context().Push(mainViewContext, onFocusOpts) + self.c.Context().Push(mainViewContext, types.OnFocusOpts{}) return nil } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 78729e18c..bde383caf 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -517,11 +517,6 @@ 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/pkg/i18n/english.go b/pkg/i18n/english.go index 30aa64017..5f426c662 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -551,6 +551,7 @@ type TranslationSet struct { EnterStaging string ExitCustomPatchBuilder string ExitFocusedMainView string + ToggleSelectionInFocusedMainView string EnterUpstream string InvalidUpstream string NewRemote string @@ -1716,6 +1717,7 @@ func EnglishTranslationSet() *TranslationSet { EnterStaging: "Enter staging/patch building", ExitCustomPatchBuilder: `Exit custom patch builder`, ExitFocusedMainView: "Exit back to side panel", + ToggleSelectionInFocusedMainView: "Show/hide selection", EnterUpstream: `Enter upstream as ' '`, InvalidUpstream: "Invalid upstream. Must be in the format ' '", NewRemote: `New remote`, diff --git a/schema-master/config.json b/schema-master/config.json index b7c6c4d6a..45a2b9efe 100644 --- a/schema-master/config.json +++ b/schema-master/config.json @@ -693,11 +693,6 @@ "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 b7c6c4d6a..45a2b9efe 100644 --- a/schema/config.json +++ b/schema/config.json @@ -693,11 +693,6 @@ "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": [