diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 3037943c5..5ed7109b2 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -473,7 +473,15 @@ func (self *FilesController) GetFocusedMainViewDiffSource() types.FocusedMainVie } func (self *FilesController) GetOnDoubleClick() func() error { - return self.enter + return self.withItemGraceful(func(node *filetree.FileNode) error { + nodes := []*filetree.FileNode{node} + if disabledReason := self.canStageSelection(nodes); disabledReason != nil { + self.c.ErrorToast(self.c.Tr.DisabledMenuItemPrefix + disabledReason.Text) + return nil + } + + return self.press(nodes) + }) } // if we are dealing with a status for which there is no key in this map, diff --git a/pkg/integration/tests/file/double_click_toggles_staging.go b/pkg/integration/tests/file/double_click_toggles_staging.go new file mode 100644 index 000000000..84386414a --- /dev/null +++ b/pkg/integration/tests/file/double_click_toggles_staging.go @@ -0,0 +1,61 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var DoubleClickTogglesStaging = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Double-clicking a file or directory toggles whether it is staged", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFile("dir/file1", "") + shell.CreateFile("dir/file2", "") + shell.CreateFile("file3", "") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Equals("▼ /").IsSelected(), + Equals(" ▼ dir"), + Equals(" ?? file1"), + Equals(" ?? file2"), + Equals(" ?? file3"), + ). + DoubleClick(6, 4). + Lines( + Equals("▼ /"), + Equals(" ▼ dir"), + Equals(" ?? file1"), + Equals(" ?? file2"), + Equals(" A file3").IsSelected(), + ). + DoubleClick(5, 1). + Lines( + Equals("▼ /"), + Equals(" ▼ dir").IsSelected(), + Equals(" A file1"), + Equals(" A file2"), + Equals(" A file3"), + ). + DoubleClick(6, 4). + Lines( + Equals("▼ /"), + Equals(" ▼ dir"), + Equals(" A file1"), + Equals(" A file2"), + Equals(" ?? file3").IsSelected(), + ). + DoubleClick(5, 1). + Lines( + Equals("▼ /"), + Equals(" ▼ dir").IsSelected(), + Equals(" ?? file1"), + Equals(" ?? file2"), + Equals(" ?? file3"), + ) + }, +}) diff --git a/pkg/integration/tests/file/stage_nested_repository.go b/pkg/integration/tests/file/stage_nested_repository.go index 7776af656..c51d64df3 100644 --- a/pkg/integration/tests/file/stage_nested_repository.go +++ b/pkg/integration/tests/file/stage_nested_repository.go @@ -38,6 +38,14 @@ var StageNestedRepository = NewIntegrationTest(NewIntegrationTestArgs{ Tap(func() { t.ExpectToast(Equals("Disabled: Can't stage 'modules/sub' because it is a git repository of its own. Discard it with d, or ignore it with i.")) }). + DoubleClick(5, 1). + Tap(func() { + t.ExpectToast(Equals("Disabled: Can't stage 'modules/sub' because it is a git repository of its own. Discard it with d, or ignore it with i.")) + }). + Lines( + Equals("?? file"), + Equals("?? modules/sub (removed submodule)").IsSelected(), + ). // Staging all files works if the nested repository is filtered out FilterOrSearch("file"). Lines( diff --git a/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go b/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go index cfcebfa57..e408dcde4 100644 --- a/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go +++ b/pkg/integration/tests/main_view/enter_and_double_click_focus_file_diff.go @@ -30,14 +30,6 @@ var EnterAndDoubleClickFocusFileDiff = NewIntegrationTest(NewIntegrationTestArgs SelectedLines(Contains("-base")). PressEscape() - t.Views().Files(). - IsFocused(). - DoubleClick(3, 0) - t.Views().Main(). - IsFocused(). - SelectedLines(Contains("-base")). - PressEscape() - t.Views().Commits(). Focus(). Lines( diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 79d40de3e..ac42aa5ae 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -297,6 +297,7 @@ var tests = []*components.IntegrationTest{ file.DiscardUnstagedRangeSelect, file.DiscardVariousChanges, file.DiscardVariousChangesRangeSelect, + file.DoubleClickTogglesStaging, file.ExcludeWithoutInfoDir, file.ExplainNestedRepositories, file.ExplainUntrackedDirectory,