fyne icon indicating copy to clipboard operation
fyne copied to clipboard

Chinese input method string truncated when typing into `widget.NewEntryWithData'

Open Czyhandsome opened this issue 3 years ago • 10 comments

I have set FYNE_FONT to support Chinese char print, but when I use Chinese input method to type something into the entry, the string gets truncated.

Code:

package main

import (
    "fmt"
    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/data/binding"
    "fyne.io/fyne/v2/dialog"
    "fyne.io/fyne/v2/widget"
    "io/ioutil"
    "os"
    "path/filepath"
    "time"
)

func main() {
    err := os.Setenv("FYNE_FONT", "C:\\Windows\\Fonts\\STSONG.TTF")
    if err != nil {
        return
    }
    a := app.New()
    w := a.NewWindow("突击")
    fileName := binding.NewString()

    entry := widget.NewEntryWithData(fileName)
    entry.OnSubmitted = func(fileName string) {
        now := time.Now().Format("20060102")
        //currentDir, err := os.Getwd()
        //if err != nil {
        //    dialog.ShowConfirm("Oops!", fmt.Sprintf("Getwd: %v", err), nil, w)
        //    return
        //}
        full := filepath.Join(fmt.Sprintf("%s - %s", now, fileName))
        // 检测当前是否存在同名目录或文件
        if _, err := os.Stat(full); err == nil {
            dialog.ShowConfirm("Oops!", fmt.Sprintf("File or directory %s exists", full), nil, w)
            return
        } else if !os.IsNotExist(err) {
            dialog.ShowConfirm("Oops!", fmt.Sprintf("Stat %s: %v", full, err), nil, w)
            return
        }
        err = os.MkdirAll(full, os.ModeDir)
        if err != nil {
            dialog.ShowConfirm("Oops!", fmt.Sprintf("Fail to create directory %s: %v", full, err), nil, w)
            return
        }
        // Write to file
        err := ioutil.WriteFile(filepath.Join(full, "README.md"), []byte(fmt.Sprintf("# %s\n", fileName)), os.ModeAppend)
        if err != nil {
            dialog.ShowConfirm("Oops!", fmt.Sprintf("Fail to WriteFile %s: %v", full, err), nil, w)
            return
        }
        dialog.ShowInformation("OK", "OK", w)
    }
    w.Resize(fyne.NewSize(400, 500))
    w.SetContent(container.NewVBox(
        widget.NewLabel("Please input tuji directory name"),
        entry,
    ))

    w.ShowAndRun()
}

gets:

expected got

Czyhandsome avatar Feb 14 '22 09:02 Czyhandsome

I also have this problem using Microsoft Pinyin input

layxyer avatar Feb 15 '22 02:02 layxyer

If possible could you please help test feature/go-text branch to see if this is a problem there as well? We are working to replace the text shaping to vastly improve international support.

andydotxyz avatar Feb 15 '22 16:02 andydotxyz

I also encountered this problem when using the MacOS version of Sogou Pinyin input

zxdstyle avatar Feb 28 '22 13:02 zxdstyle

@zxdstyle Can you please help by testing the feature/go-text branch mentioned above?

andydotxyz avatar Feb 28 '22 15:02 andydotxyz

@zxdstyle Can you please help by testing the feature/go-text branch mentioned above?

Of course, but I didn't find the branch you mentioned

zxdstyle avatar Mar 01 '22 07:03 zxdstyle

My apologise, the branch is on my fork, https://github.com/andydotxyz/fyne/commits/feature/go-text

andydotxyz avatar Mar 01 '22 09:03 andydotxyz

After my test, the branch still has the same problem

replace fyne.io/fyne/v2 v2.1.3 => github.com/andydotxyz/fyne/v2 v2.0.3-0.20220123133908-c62fd89b6c1d

ws1yd-ofks9

zxdstyle avatar Mar 01 '22 13:03 zxdstyle

It looks to me like it changed slightly - with the branch it works the first time, but then as more characters are added it breaks. Is that accurate?

andydotxyz avatar Mar 02 '22 11:03 andydotxyz

Indeed it is

zxdstyle avatar Mar 02 '22 12:03 zxdstyle

I also encountered the problem of inputting Chinese fonts, the program crashed when inputting more characters, and the input method selection box did not follow in the input box

layxyer avatar Sep 21 '22 10:09 layxyer

come here from #2660 ,yes same problem in NewMultiLineEntry

hongguozb avatar Nov 21 '22 01:11 hongguozb