From 775f5791257b141cea2dfec45e6f6c7ca145509e Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Thu, 10 Nov 2022 21:36:16 +0100 Subject: 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 Tested-by: Bence Ferdinandy --- widgets/dirtree.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'widgets/dirtree.go') 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 -- cgit