diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 81d3f4cf0..39730ae09 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -1009,10 +1009,14 @@ func normalisedSelectedNodes(selectedNodes []*filetree.FileNode) []*filetree.Fil func isDescendentOfSelectedNodes(node *filetree.FileNode, selectedNodes []*filetree.FileNode) bool { for _, selectedNode := range selectedNodes { + if selectedNode.IsFile() { + continue + } + selectedNodePath := selectedNode.GetPath() nodePath := node.GetPath() - if strings.HasPrefix(nodePath, selectedNodePath) && nodePath != selectedNodePath { + if strings.HasPrefix(nodePath, selectedNodePath+"/") { return true } } diff --git a/pkg/integration/tests/file/stage_children_range_select.go b/pkg/integration/tests/file/stage_children_range_select.go new file mode 100644 index 000000000..30a0a5e6b --- /dev/null +++ b/pkg/integration/tests/file/stage_children_range_select.go @@ -0,0 +1,45 @@ +package file + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var StageChildrenRangeSelect = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Stage a range of files/folders and their children using range select", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) { + }, + SetupRepo: func(shell *Shell) { + shell.CreateFile("foo", "") + shell.CreateFile("foobar", "") + shell.CreateFile("baz/file", "") + shell.CreateFile("bazbam/file", "") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Files(). + IsFocused(). + Lines( + Contains("▼ baz").IsSelected(), + Contains(" ??").Contains("file"), + Contains("▼ bazbam"), + Contains(" ??").Contains("file"), + Contains("??").Contains("foo"), + Contains("??").Contains("foobar"), + ). + // Select everything + Press(keys.Universal.ToggleRangeSelect). + NavigateToLine(Contains("foobar")). + // Stage + PressPrimaryAction(). + Lines( + Contains("▼ baz").IsSelected(), + Contains(" A ").Contains("file").IsSelected(), + Contains("▼ bazbam").IsSelected(), + Contains(" A ").Contains("file").IsSelected(), + Contains("A ").Contains("foo").IsSelected(), + Contains("A ").Contains("foobar").IsSelected(), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index cbd3471e5..bfc0fe786 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -160,6 +160,7 @@ var tests = []*components.IntegrationTest{ file.DiscardVariousChangesRangeSelect, file.Gitignore, file.RememberCommitMessageAfterFail, + file.StageChildrenRangeSelect, file.StageRangeSelect, filter_and_search.FilterCommitFiles, filter_and_search.FilterFiles,