fyne-io / fyne

Cross platform GUI toolkit in Go inspired by Material Design
https://fyne.io/
Other
24.05k stars 1.34k forks source link

MultiLineEntry widget Press the Ctrl+left arrow will panic #4991

Open langxlm opened 2 weeks ago

langxlm commented 2 weeks ago

Checklist

Describe the bug

I use MultiLineEntry in my windows program . when i run the process in win10, focus in that widget ,press Ctrl+left-arrow, the proecess panic .

error message fyi :

panic: runtime error: slice bounds out of range [-1:]

goroutine 53 [running]: fyne.io/fyne/v2/widget.getTextWhitespaceRegion({0xc00b550450, 0xc0004e1ef0, 0xc0004e1f00}, 0x7ff6c25208ee, 0x1) C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/widget/entry.go:1957 +0x1a9 fyne.io/fyne/v2/widget.(Entry).registerShortcut.func5({0x7ff6c37d3280, 0xc00a6e01b0}) C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/widget/entry.go:979 +0x5b fyne.io/fyne/v2/widget.(Entry).registerShortcut.func7({0x7ff6c37d3280, 0xc00a6e01b0}) C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/widget/entry.go:1016 +0x32 fyne.io/fyne/v2.(ShortcutHandler).TypedShortcut(0xc000554048, {0x7ff6c37d3280, 0xc00a6e01b0}) C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/shortcut.go:21 +0x77 fyne.io/fyne/v2/widget.(Entry).TypedShortcut(0xc00046ef00, {0x7ff6c37d3280, 0xc00a6e01b0}) C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/widget/entry.go:825 +0x29 fyne.io/fyne/v2/internal/driver/glfw.(window).triggersShortcut.func1() C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/internal/driver/glfw/window.go:906 +0x2a fyne.io/fyne/v2/internal/driver/common.(Window).RunEventQueue(0xc0000021e0) C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/internal/driver/common/window.go:35 +0x3e created by fyne.io/fyne/v2/internal/driver/glfw.(*gLDriver).createWindow.func1 C:/Users/langxli/go/pkg/mod/fyne.io/fyne/v2@v2.4.5/internal/driver/glfw/window.go:960 +0x13b

How to reproduce

go mod fyne.io/fyne/v2 v2.4.5

code : textInput := widget.NewMultiLineEntry() textInput.SetText(string(scriptContent))

Screenshots

No response

Example code

textInput := widget.NewMultiLineEntry()
textInput.SetText(string(scriptContent))

Fyne version

2.4.5

Go compiler version

go1.17

Operating system and version

Winodw10

Additional Information

No response

hfmrow commented 1 week ago

Hi, langxlm

I'm trying to learn more about your issue, but unfortunately, without any success.

Fyne version

2.4.5

Go compiler version

go1.22.5

Operating system and version

Windows 10 Entreprise LTSC v21H2 b19044.2486


Unable to reproduce

Used code (inside dev environment):

        test := widget.NewMultiLineEntry()
        test.SetText("test ctrl left")
        oldContent := mainWindow.Canvas().Content()
        mainWindow.SetContent(test)
        mainWindow.Show()

        go func(oC fyne.CanvasObject) {
            time.Sleep(time.Second * 15)
            mainWindow.SetContent(oldContent)

        }(oldContent)

Animation

keys used: [ctrl+left and right arrow], [ctrl+shift+left and right arrow]

work well...

only go version (1.22.5) change

andydotxyz commented 1 week ago

I also cannot replicate this issue. Is it possible that it relates to the un-shared scriptContent bytes?

langxlm commented 1 week ago

thx all ! i found the problem .

func getTextWhitespaceRegion(row []rune, col int, expand bool) (int, int)

this funtion when col is zero , will cause the endCheck is -1 , and then slice out of range . end := strings.IndexByte(toks[endCheck:], c)

so when press the ctrl+left in a empty row , will occur this panic. @andydotxyz @hfmrow

andydotxyz commented 1 week ago

Looking at the code this has already been solved in #4662. I recommend testing against v2.5.0-rc1 to check.