Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single line Entry throws away selected text on submission #4026

Closed
2 tasks done
Goltanju opened this issue Jul 4, 2023 · 3 comments
Closed
2 tasks done

Single line Entry throws away selected text on submission #4026

Goltanju opened this issue Jul 4, 2023 · 3 comments
Labels
unverified A bug that has been reported but not verified

Comments

@Goltanju
Copy link
Contributor

Goltanju commented Jul 4, 2023

Checklist

  • I have searched the issue tracker for open issues that relate to the same problem, before opening a new one.
  • This issue only relates to a single bug. I will open new issues for any other problems.

Describe the bug

Pretty much the title, fairly simple bug I think. The single line entry will discard any selected text on submit.

How to reproduce

With a single line entry:

  1. Type in "abc" and hit enter: you get "abc" ✔️
  2. Type in "abc" hit ctrl+a to select all and hit enter: you get "" 😢
  3. Type in "abc" select just the b and hit enter: you get "ac" 😢

Screenshots

No response

Example code

package main

import (
        "fmt"
        "image/color"

        "fyne.io/fyne/v2"
        "fyne.io/fyne/v2/app"
        "fyne.io/fyne/v2/canvas"
        "fyne.io/fyne/v2/container"
        "fyne.io/fyne/v2/theme"
        "fyne.io/fyne/v2/widget"
)

func main() {
        application := app.NewWithID("test-gui")
        window := application.NewWindow("Test GUI")
        monospace := fyne.MeasureText("M", theme.TextSize(), fyne.TextStyle{Monospace: true})
        min := canvas.NewRectangle(color.RGBA{})
        min.SetMinSize(fyne.NewSize(monospace.Width*20, monospace.Height*5))
        entry := widget.NewEntry()
        label := widget.NewLabel("")
        entry.OnSubmitted = func(v string) {
                label.SetText(fmt.Sprintf("%q", v))
        }
        window.SetContent(container.NewMax(min, container.NewGridWithRows(2, entry, label)))
        window.Show()
        application.Run()
}

Fyne version

develop

Go compiler version

1.20.5

Operating system and version

Windows 11

Additional Information

No response

@Goltanju Goltanju added the unverified A bug that has been reported but not verified label Jul 4, 2023
@Goltanju
Copy link
Contributor Author

Goltanju commented Jul 4, 2023

This patch seems to fix the problem, but I don't really know if it's the correct approach:

diff --git a/widget/entry.go b/widget/entry.go
index 41967616e..5ada3d289 100644
--- a/widget/entry.go
+++ b/widget/entry.go
@@ -1028,7 +1028,9 @@ func (e *Entry) selectingKeyHandler(key *fyne.KeyEvent) bool {
                return true
        case fyne.KeyReturn, fyne.KeyEnter:
                // clear the selection -- return unhandled to add the newline
-               e.eraseSelection()
+               if e.MultiLine {
+                       e.eraseSelection()
+               }
                return false
        }

@andydotxyz
Copy link
Member

Good catch.
A sensible fix - though it would need unit tests as well to confirm fix and avoid regressions.

andydotxyz added a commit that referenced this issue Jul 11, 2023
widget: Single line Entry: Submit should include selected text. (#4026)
@andydotxyz
Copy link
Member

Fix landed on develop, thanks so much @Goltanju

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unverified A bug that has been reported but not verified
Projects
None yet
Development

No branches or pull requests

2 participants