mirror of
https://github.com/rivo/tview.git
synced 2024-11-12 19:10:28 +00:00
Space will also select a node in a TreeView. Resolves #280
This commit is contained in:
parent
d14da4f46f
commit
7cc6943d5a
22
treeview.go
22
treeview.go
@ -656,6 +656,17 @@ func (t *TreeView) Draw(screen tcell.Screen) {
|
||||
// InputHandler returns the handler for this primitive.
|
||||
func (t *TreeView) InputHandler() func(event *tcell.EventKey, setFocus func(p Primitive)) {
|
||||
return t.WrapInputHandler(func(event *tcell.EventKey, setFocus func(p Primitive)) {
|
||||
selectNode := func() {
|
||||
if t.currentNode != nil {
|
||||
if t.selected != nil {
|
||||
t.selected(t.currentNode)
|
||||
}
|
||||
if t.currentNode.selected != nil {
|
||||
t.currentNode.selected()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Because the tree is flattened into a list only at drawing time, we also
|
||||
// postpone the (selection) movement to drawing time.
|
||||
switch key := event.Key(); key {
|
||||
@ -681,16 +692,11 @@ func (t *TreeView) InputHandler() func(event *tcell.EventKey, setFocus func(p Pr
|
||||
t.movement = treeDown
|
||||
case 'k':
|
||||
t.movement = treeUp
|
||||
case ' ':
|
||||
selectNode()
|
||||
}
|
||||
case tcell.KeyEnter:
|
||||
if t.currentNode != nil {
|
||||
if t.selected != nil {
|
||||
t.selected(t.currentNode)
|
||||
}
|
||||
if t.currentNode.selected != nil {
|
||||
t.currentNode.selected()
|
||||
}
|
||||
}
|
||||
selectNode()
|
||||
}
|
||||
|
||||
t.process()
|
||||
|
Loading…
Reference in New Issue
Block a user