mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-05-22 10:15:43 +02:00
Add support for clicking on arrows in the file list to expand/collapse directories
Co-authored-by: Stefan Haller <stefan@haller-berlin.de>
This commit is contained in:
committed by
Stefan Haller
parent
4567840198
commit
ee3bb06b2a
@@ -142,6 +142,30 @@ func (self *CommitFilesController) context() *context.CommitFilesContext {
|
|||||||
return self.c.Contexts().CommitFiles
|
return self.c.Contexts().CommitFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *CommitFilesController) GetOnClick() func(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
return func(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
clickedIdx := self.context().GetSelectedLineIdx()
|
||||||
|
node := self.context().CommitFileTreeViewModel.Get(clickedIdx)
|
||||||
|
if node == nil || node.File != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// The arrow is at column visualDepth*2 (after indentation of 2 spaces per level).
|
||||||
|
// Only treat clicks on the arrow and the trailing space as arrow clicks.
|
||||||
|
visualDepth := self.context().CommitFileTreeViewModel.GetVisualDepth(clickedIdx)
|
||||||
|
arrowStartCol := visualDepth * 2
|
||||||
|
arrowEndCol := arrowStartCol + 1
|
||||||
|
if opts.X < arrowStartCol || opts.X > arrowEndCol {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.context().CommitFileTreeViewModel.ToggleCollapsed(node.GetInternalPath())
|
||||||
|
self.c.PostRefreshUpdate(self.context())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *CommitFilesController) GetOnRenderToMain() func() {
|
func (self *CommitFilesController) GetOnRenderToMain() func() {
|
||||||
return func() {
|
return func() {
|
||||||
node := self.context().GetSelected()
|
node := self.context().GetSelected()
|
||||||
|
|||||||
@@ -229,6 +229,30 @@ func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *FilesController) GetOnClick() func(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
return func(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
clickedIdx := self.context().GetSelectedLineIdx()
|
||||||
|
node := self.context().FileTreeViewModel.Get(clickedIdx)
|
||||||
|
if node == nil || node.File != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// The arrow is at column visualDepth*2 (after indentation of 2 spaces per level).
|
||||||
|
// Only treat clicks on the arrow and the trailing space as arrow clicks.
|
||||||
|
visualDepth := self.context().FileTreeViewModel.GetVisualDepth(clickedIdx)
|
||||||
|
arrowStartCol := visualDepth * 2
|
||||||
|
arrowEndCol := arrowStartCol + 1
|
||||||
|
if opts.X < arrowStartCol || opts.X > arrowEndCol {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
self.context().FileTreeViewModel.ToggleCollapsed(node.GetInternalPath())
|
||||||
|
self.c.PostRefreshUpdate(self.context())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *FilesController) GetOnRenderToMain() func() {
|
func (self *FilesController) GetOnRenderToMain() func() {
|
||||||
return func() {
|
return func() {
|
||||||
self.c.Helpers().Diff.WithDiffModeCheck(func() {
|
self.c.Helpers().Diff.WithDiffModeCheck(func() {
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/config"
|
||||||
|
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ClickArrowToCollapse = NewIntegrationTest(NewIntegrationTestArgs{
|
||||||
|
Description: "Click the arrow on a directory to collapse/expand it",
|
||||||
|
ExtraCmdArgs: []string{},
|
||||||
|
Skip: false,
|
||||||
|
SetupConfig: func(config *config.AppConfig) {},
|
||||||
|
SetupRepo: func(shell *Shell) {
|
||||||
|
shell.CreateDir("dir")
|
||||||
|
shell.CreateFile("dir/file-one", "original content\n")
|
||||||
|
shell.CreateDir("dir2")
|
||||||
|
shell.CreateFile("dir2/file-two", "original content\n")
|
||||||
|
},
|
||||||
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
|
t.Views().Files().
|
||||||
|
IsFocused().
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /").IsSelected(),
|
||||||
|
Equals(" ▼ dir"),
|
||||||
|
Equals(" ?? file-one"),
|
||||||
|
Equals(" ▼ dir2"),
|
||||||
|
Equals(" ?? file-two"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Click the arrow on "dir" (row 1, column 2) to collapse it
|
||||||
|
t.Views().Files().
|
||||||
|
Click(2, 1).
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /"),
|
||||||
|
Equals(" ▶ dir").IsSelected(),
|
||||||
|
Equals(" ▼ dir2"),
|
||||||
|
Equals(" ?? file-two"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Click one to the right of the arrow on "dir2" (row 2, column 3) to collapse it
|
||||||
|
// Arrow + space after should register a collapse toggle
|
||||||
|
t.Views().Files().
|
||||||
|
Click(3, 2).
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /"),
|
||||||
|
Equals(" ▶ dir"),
|
||||||
|
Equals(" ▶ dir2").IsSelected(),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Click one to the left of the arrow on "dir2" (row 2, column 1)
|
||||||
|
// Space before arrow should not register a collapse toggle
|
||||||
|
t.Views().Files().
|
||||||
|
Click(1, 2).
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /"),
|
||||||
|
Equals(" ▶ dir"),
|
||||||
|
Equals(" ▶ dir2").IsSelected(),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Clicking on the file/directory name "dir" should change selected but not toggle collapse
|
||||||
|
t.Views().Files().
|
||||||
|
Click(5, 1).
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /"),
|
||||||
|
Equals(" ▶ dir").IsSelected(),
|
||||||
|
Equals(" ▶ dir2"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Click the arrow again to expand it
|
||||||
|
t.Views().Files().
|
||||||
|
Click(2, 1).
|
||||||
|
Lines(
|
||||||
|
Equals("▼ /"),
|
||||||
|
Equals(" ▼ dir").IsSelected(),
|
||||||
|
Equals(" ?? file-one"),
|
||||||
|
Equals(" ▶ dir2"),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Click the arrow on the root "/" (row 0, column 0) to collapse everything
|
||||||
|
t.Views().Files().
|
||||||
|
Click(0, 0).
|
||||||
|
Lines(
|
||||||
|
Equals("▶ /").IsSelected(),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -210,6 +210,7 @@ var tests = []*components.IntegrationTest{
|
|||||||
diff.DiffNonStickyRange,
|
diff.DiffNonStickyRange,
|
||||||
diff.IgnoreWhitespace,
|
diff.IgnoreWhitespace,
|
||||||
diff.RenameSimilarityThresholdChange,
|
diff.RenameSimilarityThresholdChange,
|
||||||
|
file.ClickArrowToCollapse,
|
||||||
file.CollapseExpand,
|
file.CollapseExpand,
|
||||||
file.CopyMenu,
|
file.CopyMenu,
|
||||||
file.DirWithUntrackedFile,
|
file.DirWithUntrackedFile,
|
||||||
|
|||||||
Reference in New Issue
Block a user