sciter-sdk / go-sciter

Golang bindings of Sciter: the Embeddable HTML/CSS/script engine for modern UI development
https://sciter.com
2.57k stars 269 forks source link

Text() didn't work for htmlarea #177

Open coolit opened 5 years ago

coolit commented 5 years ago

The tiscript way worked, but Text() didn't . The test code is as follows:

package main

import (
    "log"

    "github.com/sciter-sdk/go-sciter"
    "github.com/sciter-sdk/go-sciter/window"
)

var html = `

<html>
    <head>
        <title>Test</title>
        <style>
        plaintext.simple > text { margin:0; padding:0; display:block; background:none; color:inherit;}

        </style>
        <script type="text/tiscript">

event click $(button#set) {
  $(#ha).value = "<p>this is <span style='background-color:#FFF18C'>test</span> for now.</p>";
}

event click $(button#gets) {
  var str = $(#ha).text;
  $(pre).value = str;
  stdout.println(str);
}
        </script>
    </head>
    <body>
<button#set>Set HTML</button>
<button#get>Get Text (Go)</button>
<button#gets>Get Text (Script)</button>

<htmlarea #ha>
  test
</htmlarea>

<pre/>

    </body>
</html>

`

func main() {
    w, err := window.New(sciter.SW_TITLEBAR|
        sciter.SW_RESIZEABLE|
        sciter.SW_CONTROLS|
        sciter.SW_MAIN|
        sciter.SW_ENABLE_DEBUG,
        nil)
    if err != nil {
        log.Fatal(err)
    }
    w.LoadHtml(html, "")
    w.SetTitle("Hello world")
    root, _ := w.GetRootElement()
    get, _ := root.SelectFirst("#get")
    get.OnClick(func() {
        ha, _ := root.SelectFirst("#ha")
        str, _ := ha.Text()
        //      str, _ := ha.Html(false)
        pre, _ := root.SelectFirst("pre")
        pre.SetHtml(str, 0)
    })

    w.Show()
    w.Run()
}
pravic commented 5 years ago

@c-smile Reproduced with Go and Rust. Looks like a Sciter's issue.

The SciterGetElementTextCB returns empty text from the <htmlarea> if its value contains HTML markup (if it contains some plain text, it works well though). While on the script side the Element.text always returns plain text.

Element.text property:

For compound elements this property returns plain-text version of the content