package ui import ( "log" "syscall/js" "unicode/utf8" ) // rmueller's version from: // ://stackoverflow.com/questions/1752414/how-to-reverse-a-string-in-go?page=1&tab=scoredesc#tab-top func reverseString(s string) string { size := len(s) buf := make([]byte, size) for start := 0; start < size; { r, n := utf8.DecodeRuneInString(s[start:]) start += n utf8.EncodeRune(buf[size-start:], r) } return string(buf) } func (ti *TextInput) Focus(focus bool) { ti.focused = focus log.Printf("%v set focus: %v\n", ti, focus) if focus { d := js.Global().Get("document") i := d.Call("getElementById", "hiddenInput") // i.Call("focus", map[string]any{"preventScroll": true, "focusVisible": false}) i.Call("focus") log.Println("open keyboard") log.Printf("set hidden input value to %s", ti.Text()) // i.Set("value", ti.Text()) i.Set("value", reverseString(ti.Text())) } } func (ti *TextInput) Update() error { if ti.focused { d := js.Global().Get("document") i := d.Call("getElementById", "hiddenInput") // t := i.Get("value").String() t := reverseString(i.Get("value").String()) ti.SetInput(t) } return nil } func (*TextInput) IsUpdatable() bool { return true }