diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-11-10 21:36:16 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-11-13 17:14:04 +0100 |
commit | 775f5791257b141cea2dfec45e6f6c7ca145509e (patch) | |
tree | 2a36eaa8a2621b407348526529b25278ba9dc0bb /widgets/dirtree.go | |
parent | 40cc540357d92aee07fba2819801e168d3bf0f33 (diff) | |
download | aerc-775f5791257b141cea2dfec45e6f6c7ca145509e.tar.gz |
dirtree: fix mouse support for selecting folders
Fix mouse support for selecting folders. Toggle foldable directories to
expand or collapse when clicked on.
Fixes: https://todo.sr.ht/~rjarry/aerc/99
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'widgets/dirtree.go')
-rw-r--r-- | widgets/dirtree.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/widgets/dirtree.go b/widgets/dirtree.go index 3d0b167b..8a3dab6f 100644 --- a/widgets/dirtree.go +++ b/widgets/dirtree.go @@ -137,22 +137,29 @@ func (dt *DirectoryTree) MouseEvent(localX int, localY int, event tcell.Event) { dt.Select(clickedDir) } case tcell.WheelDown: - dt.Next() + dt.NextPrev(1) case tcell.WheelUp: - dt.Prev() + dt.NextPrev(-1) } } } func (dt *DirectoryTree) Clicked(x int, y int) (string, bool) { - if dt.list == nil || len(dt.list) == 0 || dt.countVisible(dt.list) < y { + if dt.list == nil || len(dt.list) == 0 || dt.countVisible(dt.list) < y+dt.Scroll() { return "", false } - for i, node := range dt.list { - if dt.countVisible(dt.list[:i]) == y { + visible := 0 + for _, node := range dt.list { + if isVisible(node) { + visible++ + } + if visible == y+dt.Scroll()+1 { if path := dt.getDirectory(node); path != "" { return path, true } + node.Hidden = !node.Hidden + dt.Invalidate() + return "", false } } return "", false |