Skip to content

Commit

Permalink
Fixup tap scrolls to top on first selection (#5481)
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz authored Jan 31, 2025
1 parent 4e77e09 commit c098d33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 5 additions & 5 deletions widget/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,14 +876,14 @@ func (n *treeNode) Tapped(*fyne.PointEvent) {
}

n.tree.Select(n.uid)
if !fyne.CurrentDevice().IsMobile() {
canvas := fyne.CurrentApp().Driver().CanvasForObject(n.tree)
if canvas != nil {
canvas := fyne.CurrentApp().Driver().CanvasForObject(n.tree)
if canvas != nil && canvas.Focused() != n.tree {
n.tree.currentFocus = n.uid
if !fyne.CurrentDevice().IsMobile() {
canvas.Focus(n.tree)
}
n.tree.currentFocus = n.uid
n.Refresh()
}
n.Refresh()
}

func (n *treeNode) partialRefresh() {
Expand Down
2 changes: 2 additions & 0 deletions widget/tree_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ func TestTree_Tap(t *testing.T) {

test.Tap(getBranch(t, tree, "A"))
assert.True(t, selected, "Branch should have been selected")
assert.Equal(t, "A", tree.currentFocus)
})
t.Run("BranchIcon", func(t *testing.T) {
data := make(map[string][]string)
Expand Down Expand Up @@ -725,6 +726,7 @@ func TestTree_Tap(t *testing.T) {
}
test.Tap(getLeaf(t, tree, "A"))
assert.True(t, selected, "Leaf should have been selected")
assert.Equal(t, "A", tree.currentFocus)
})
}

Expand Down

0 comments on commit c098d33

Please sign in to comment.