Skip to content

Commit

Permalink
widget.Entry: validate when pasting from clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre authored and andydotxyz committed Oct 10, 2024
1 parent 19d9c1e commit be4d8e5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions widget/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,7 @@ func (e *Entry) pasteFromClipboard(clipboard fyne.Clipboard) {
cb := e.OnChanged
e.propertyLock.Unlock()

e.validate()
if cb != nil {
cb(content) // We know that the text has changed.
}
Expand Down
22 changes: 22 additions & 0 deletions widget/entry_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,28 @@ func TestEntry_PasteFromClipboard_MultilineWrapping(t *testing.T) {
assert.Equal(t, 7, entry.CursorColumn)
}

func TestEntry_PasteFromClipboardValidation(t *testing.T) {
entry := NewEntry()
var triggered int
entry.Validator = func(s string) error {
triggered++
return nil
}

w := test.NewApp().NewWindow("")
defer w.Close()
w.SetContent(entry)

testContent := "test"

clipboard := fyne.CurrentApp().Driver().AllWindows()[0].Clipboard()
clipboard.SetContent(testContent)

entry.pasteFromClipboard(clipboard)

assert.Equal(t, 2, triggered)
}

func TestEntry_PlaceholderTextStyle(t *testing.T) {
e := NewEntry()
e.TextStyle = fyne.TextStyle{Bold: true, Italic: true}
Expand Down

0 comments on commit be4d8e5

Please sign in to comment.