summaryrefslogtreecommitdiffstats
path: root/pkg/integration
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2024-01-02 12:19:31 +1100
committerJesse Duffield <jessedduffield@gmail.com>2024-01-28 08:33:13 +1100
commit0f9d9e13d12d37ab419efccc5c217422fb67a765 (patch)
tree35fc5bdc4473da8a6750ee621e270b9e595520c9 /pkg/integration
parentc07b3fad64ca71bc1873bcc1bb9e2256c05d4df0 (diff)
Show mode-specific keybinding suggestions
As part of making lazygit more discoverable, there are certain keys which you almost certainly need to press when you're in a given mode e.g. 'v' to paste commits when cherry-picking. This commit prominently shows these keybinding suggestions alongside the others in the option view. I'm using the same colours for these keybindings as is associated with the mode elsewhere e.g. yellow for rebasing and cyan for cherry-picking. The cherry-picking one is a bit weird because we also use cyan text to show loaders and app status at the bottom left so it may be confusing, but I haven't personally found it awkward from having tested it out myself. Previously we would render these options whenever a new context was activated, but now that we need to re-render options whenever a mode changes, I'm instead rendering them on each screen re-render (i.e. in the layout function). Given how cheap it is to render this text, I think it's fine performance-wise.
Diffstat (limited to 'pkg/integration')
-rw-r--r--pkg/integration/components/common.go26
-rw-r--r--pkg/integration/components/views.go4
-rw-r--r--pkg/integration/tests/test_list.go1
-rw-r--r--pkg/integration/tests/ui/mode_specific_keybinding_suggestions.go118
4 files changed, 149 insertions, 0 deletions
diff --git a/pkg/integration/components/common.go b/pkg/integration/components/common.go
index 4f7cd9754..2033a9442 100644
--- a/pkg/integration/components/common.go
+++ b/pkg/integration/components/common.go
@@ -62,3 +62,29 @@ func (self *Common) SelectPatchOption(matcher *TextMatcher) {
self.t.ExpectPopup().Menu().Title(Equals("Patch options")).Select(matcher).Confirm()
}
+
+func (self *Common) ResetBisect() {
+ self.t.Views().Commits().
+ Focus().
+ Press(self.t.keys.Commits.ViewBisectOptions).
+ Tap(func() {
+ self.t.ExpectPopup().Menu().
+ Title(Equals("Bisect")).
+ Select(Contains("Reset bisect")).
+ Confirm()
+
+ self.t.ExpectPopup().Confirmation().
+ Title(Equals("Reset 'git bisect'")).
+ Content(Contains("Are you sure you want to reset 'git bisect'?")).
+ Confirm()
+ })
+}
+
+func (self *Common) ResetCustomPatch() {
+ self.t.GlobalPress(self.t.keys.Universal.CreatePatchOptionsMenu)
+
+ self.t.ExpectPopup().Menu().
+ Title(Equals("Patch options")).
+ Select(Contains("Reset patch")).
+ Confirm()
+}
diff --git a/pkg/integration/components/views.go b/pkg/integration/components/views.go
index edb2b85b6..873aca650 100644
--- a/pkg/integration/components/views.go
+++ b/pkg/integration/components/views.go
@@ -147,3 +147,7 @@ func (self *Views) Search() *ViewDriver {
func (self *Views) Tooltip() *ViewDriver {
return self.regularView("tooltip")
}
+
+func (self *Views) Options() *ViewDriver {
+ return self.regularView("options")
+}
diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go
index 2406b2f78..f4693faef 100644
--- a/pkg/integration/tests/test_list.go
+++ b/pkg/integration/tests/test_list.go
@@ -269,6 +269,7 @@ var tests = []*components.IntegrationTest{
ui.Accordion,
ui.DoublePopup,
ui.EmptyMenu,
+ ui.ModeSpecificKeybindingSuggestions,
ui.OpenLinkFailure,
ui.RangeSelect,
ui.SwitchTabFromMenu,
diff --git a/pkg/integration/tests/ui/mode_specific_keybinding_suggestions.go b/pkg/integration/tests/ui/mode_specific_keybinding_suggestions.go
new file mode 100644
index 000000000..f11e5fd27
--- /dev/null
+++ b/pkg/integration/tests/ui/mode_specific_keybinding_suggestions.go
@@ -0,0 +1,118 @@
+package ui
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/config"
+ . "github.com/jesseduffield/lazygit/pkg/integration/components"
+ "github.com/jesseduffield/lazygit/pkg/integration/tests/shared"
+)
+
+var ModeSpecificKeybindingSuggestions = NewIntegrationTest(NewIntegrationTestArgs{
+ Description: "When in various modes, we should corresponding keybinding suggestions onscreen",
+ ExtraCmdArgs: []string{},
+ Skip: false,
+ SetupConfig: func(config *config.AppConfig) {},
+ SetupRepo: func(shell *Shell) {
+ shell.CreateNCommits(2)
+ shell.NewBranch("base-branch")
+ shared.MergeConflictsSetup(shell)
+ shell.Checkout("base-branch")
+ },
+ Run: func(t *TestDriver, keys config.KeybindingConfig) {
+ rebaseSuggestion := "View rebase options: m"
+ cherryPickSuggestion := "Paste (cherry-pick): V"
+ bisectSuggestion := "View bisect options: b"
+ customPatchSuggestion := "View custom patch options: <c-p>"
+ mergeSuggestion := "View merge options: m"
+
+ t.Views().Commits().
+ Focus().
+ Lines(
+ Contains("commit 02").IsSelected(),
+ Contains("commit 01"),
+ ).
+ Tap(func() {
+ // These suggestions are mode-specific so are not shown by default
+ t.Views().Options().Content(
+ DoesNotContain(rebaseSuggestion).
+ DoesNotContain(mergeSuggestion).
+ DoesNotContain(cherryPickSuggestion).
+ DoesNotContain(bisectSuggestion).
+ DoesNotContain(customPatchSuggestion),
+ )
+ }).
+ // Start an interactive rebase
+ Press(keys.Universal.Edit).
+ Tap(func() {
+ // Confirm the rebase suggestion now appears
+ t.Views().Options().Content(Contains(rebaseSuggestion))
+ }).
+ Press(keys.Commits.CherryPickCopy).
+ Tap(func() {
+ // Confirm the cherry pick suggestion now appears
+ t.Views().Options().Content(Contains(cherryPickSuggestion))
+ // Importantly, we show multiple of these suggestions at once
+ t.Views().Options().Content(Contains(rebaseSuggestion))
+ }).
+ // Cancel the cherry pick
+ PressEscape().
+ Tap(func() {
+ t.Views().Options().Content(DoesNotContain(cherryPickSuggestion))
+ }).
+ // Cancel the rebase
+ Tap(func() {
+ t.Common().AbortRebase()
+
+ t.Views().Options().Content(DoesNotContain(rebaseSuggestion))
+ }).
+ Press(keys.Commits.ViewBisectOptions).
+ Tap(func() {
+ t.ExpectPopup().Menu().
+ Title(Equals("Bisect")).
+ Select(MatchesRegexp("Mark.* as bad")).
+ Confirm()
+
+ t.Views().Options().Content(Contains(bisectSuggestion))
+
+ // Cancel bisect
+ t.Common().ResetBisect()
+
+ t.Views().Options().Content(DoesNotContain(bisectSuggestion))
+ }).
+ // Enter commit files view
+ PressEnter()
+
+ t.Views().CommitFiles().
+ IsFocused().
+ // Add a commit file to the patch
+ Press(keys.Universal.Select).
+ Tap(func() {
+ t.Views().Options().Content(Contains(customPatchSuggestion))
+
+ t.Common().ResetCustomPatch()
+
+ t.Views().Options().Content(DoesNotContain(customPatchSuggestion))
+ })
+
+ // Test merge options suggestion
+ t.Views().Branches().
+ Focus().
+ NavigateToLine(Contains("first-change-branch")).
+ Press(keys.Universal.Select).
+ NavigateToLine(Contains("second-change-branch")).
+ Press(keys.Branches.MergeIntoCurrentBranch).
+ Tap(func() {
+ t.ExpectPopup().Confirmation().
+ Title(Equals("Merge")).
+ Content(Contains("Are you sure you want to merge")).
+ Confirm()
+
+ t.Common().AcknowledgeConflicts()
+
+ t.Views().Options().Content(Contains(mergeSuggestion))
+
+ t.Common().AbortMerge()
+
+ t.Views().Options().Content(DoesNotContain(mergeSuggestion))
+ })
+ },
+})