Redesign default tree controls

This commit is contained in:
Storm Dragon
2026-09-05 00:34:40 -04:00
parent db2d441dfc
commit ef19a558d2
7 changed files with 160 additions and 31 deletions
+21
View File
@@ -1,6 +1,7 @@
package uiterm
import (
"reflect"
"testing"
"time"
)
@@ -15,6 +16,26 @@ func (i *cyclicItem) TreeItemStyle(fg, bg Attribute, active bool) (Attribute, At
return fg, bg
}
func TestTreePassesLeftRightAndBackspaceToFocusedItem(t *testing.T) {
item := &cyclicItem{name: "user"}
var received []Key
tree := Tree{
KeyListener: func(_ *Ui, _ *Tree, _ TreeItem, key Key) {
received = append(received, key)
},
lines: []renderedTreeItem{{Item: item}},
}
tree.uiInitialize(New(nil))
for _, key := range []Key{KeyArrowLeft, KeyArrowRight, KeyBackspace, KeyBackspace2} {
tree.uiKeyEvent(key)
}
want := []Key{KeyArrowLeft, KeyArrowRight, KeyBackspace, KeyBackspace2}
if !reflect.DeepEqual(received, want) {
t.Fatalf("tree keys = %v, want %v", received, want)
}
}
// Regression: rebuild_rec followed parent/child links with no depth limit, so
// a cyclic channel graph recursed until the process ran out of memory. A
// rebuild must now terminate and stay bounded.