Skip to content

Commit

Permalink
Merge pull request #4830 from dweymouth/fix-hyperlink-tap
Browse files Browse the repository at this point in the history
Fix regression of hyperlink tap rejection if outside text area
  • Loading branch information
dweymouth committed May 4, 2024
2 parents 8a05d1c + 0298139 commit aecc4f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions widget/hyperlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func (hl *Hyperlink) SetURLFromString(str string) error {

// Tapped is called when a pointer tapped event is captured and triggers any change handler
func (hl *Hyperlink) Tapped(e *fyne.PointEvent) {
if len(hl.provider.Segments) != 0 && !hl.isPosOverText(e.Position) {
return // tapped outside text area
}
hl.invokeAction()
}

Expand Down
13 changes: 13 additions & 0 deletions widget/hyperlink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ func TestHyperlink_OnTapped(t *testing.T) {
assert.Equal(t, 1, tapped)
}

func TestHyperlink_TappedOutsideTextBoundary(t *testing.T) {
tapped := 0
link := &Hyperlink{Text: "Test"}
link.OnTapped = func() {
tapped++
}
link.syncSegments()
link.Tapped(&fyne.PointEvent{
Position: fyne.NewPos(50 /*past text boundary*/, 2),
})
assert.Equal(t, 0, tapped)
}

func TestHyperlink_KeyboardOnTapped(t *testing.T) {
tapped := 0
link := &Hyperlink{Text: "Test"}
Expand Down

0 comments on commit aecc4f0

Please sign in to comment.